我如何强制在 git pull 上覆盖本地文件 ? 我的本地仓库包含一个与服务器相同的文件名文件 。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
我如何强制在 git pull 上覆盖本地文件 ? 我的本地仓库包含一个与服务器相同的文件名文件 。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
当前回答
另一种解决的方法 就是先用 Git 隐藏来隐藏任何未承诺的更改, 然后运行
git pull --rebase=interactive -s recursive -X theirs
在交互式的重新基点中,您可以改变您本地所有不想要的放弃承诺, 这将摆脱它们, 并离开您在远程分支的头部, 而不引入合并承诺 。
现在,你可以运行git 藏品申请 如果你有本地藏品 更改了您想要带回来。
其他回答
将索引和头重置为源/ 主机,但不重置工作树 :
git reset origin/master
对于那些不喜欢重置的人,我喜欢这样的做法:
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
最顶尖的答案会给有类似问题的人带来问题, 但不想失去本地文件。 例如,
以下版本将您本地的更改引入临时分支( tmp) , 检查原始分支( 我假设是母分支) 并合并更新 。 您可以用隐藏来做到这一点, 但我发现通常更容易使用分支/ 合并方法 。
git checkout -b tmp
git add *; git commit -am "my temporary files"
git checkout master
git fetch origin master
git merge -s recursive -X theirs origin master
假设另一个仓库是源主
1: 重置为上一个承诺
git reset --hard HEAD
2: 删除未跟踪的文件
git clean -f
3:拉起承诺
git pull
资料来源:
http://git-scm.com/docs/git-reset https://git-scm.com/docs/git-clean/
我有一个类似的问题。 我必须这样做:
git reset --hard HEAD
git clean -f
git pull