我如何强制在 git pull 上覆盖本地文件 ? 我的本地仓库包含一个与服务器相同的文件名文件 。

错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖


当前回答

我试图在三角2网块启动器上使用材料2分支, 并且有一段很愉快的时间。 这是我唯一可以下载和使用该分支的方法。

git clone --depth 1 https://github.com/angularclass/angular2-webpack-starter.git

cd angular2-webpack-starter/

git checkout -b material2

打开工程文件夹, 删除所有非隐藏的文件和文件夹。 留下所有隐藏的文件和文件夹 。

git add .

git commit -m "pokemon go"

git reset --hard

git pull origin material2

(当编辑器弹出时, 点击 ': wq' , 然后按进)

现在你准备好了

其他回答

只是做做

git fetch origin branchname
git checkout -f origin/branchname // This will overwrite ONLY new included files
git checkout branchname
git merge origin/branchname

来避免所有不想要的副作用,例如删除您想要保存的文件或目录等。

对于那些不喜欢重置的人,我喜欢这样的做法:


git checkout branchname      # go to your branch
git fetch origin branchname  # fetch the remote
git checkout -b backup       # optionally, mark your remote as a backup
git branch -f branchname origin/branchname # force your local branch to be equal to the fetched origin/branchname


我读过所有答案,但我在找一个命令来做这个。 这就是我所做的。在.gitconfig 中添加了一个 Git 化名。

[alias]
      fp = "!f(){ git fetch ${1} ${2} && git reset --hard ${1}/${2};};f"

您的命令以

git fp origin master

等于

git fetch origin master
git reset --hard origin/master

我也有同样的问题 没人给我这个解决方案 但对我有用

我用下列方法解决了问题:

删除所有文件。 仅留下. git 目录。 git 重置 -- hard head git pull git push

现在起作用了

看起来最好的办法是首先做到:

git clean

以删除所有未跟踪的文件,然后继续使用通常的 Git 调用...