我如何强制将本地文件覆盖在git pull
我的本地仓库包含一个文件名文件名与服务器上的文件名相同。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
我如何强制将本地文件覆盖在git pull
我的本地仓库包含一个文件名文件名与服务器上的文件名相同。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
当前回答
对于那些不喜欢的人reset
我喜欢这个方法:
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
其他回答
警告,如果您在 gitignore 文件中有任何目录/ * 条目, 这样做将永久删除您的文件 。
有些答案似乎很可怕。 从发生在Lauri身上的可怕意义来看,
相反(给予 > v1.7.6):
git stash --include-untracked
git pull
稍后,您可以清理藏匿历史。
手动,一对一:
$ git stash list
stash@{0}: WIP on <branch>: ...
stash@{1}: WIP on <branch>: ...
$ git stash drop stash@{0}
$ git stash drop stash@{1}
残酷地说,所有 - 一次:
$ git stash clear
当然,如果你想回到你藏的东西:
$ git stash list
...
$ git stash apply stash@{5}
我也有同样的问题,而且出于某种原因,git clean -f -d
这就是为什么:出于某种原因, 如果你的档案被Git(通过.gitignore 条目,我想,通过.gitignore 条目)忽略了, 它仍然费了时间,拉拉拉,但一个清洁除非添加, 否则不会删除它-x
.
对于那些不喜欢的人reset
我喜欢这个方法:
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
我总结了其他答案 你可以执行git pull
无错误 :
git fetch --all
git reset --hard origin/master
git reset --hard HEAD
git clean -f -d
git pull
警告警告警告警告:这个脚本非常强大,所以你可能会失去变化。
一旦您进行了 Git 拖动, 您就会得到不匹配的文件列表。 如果文件数量不大, 那么您就可以检查这些文件, 此动作将会覆盖这些文件 。
git 检出 - <filename>
我通常会这样做, 如果为了快速检查, 我修改服务器上的本地文件( 没有推荐的, 以及您在获取此议题: D 背后的理由) , 我找到解决方案后会检查被修改的文件 。