我如何强制将本地文件覆盖在git pull
我的本地仓库包含一个文件名文件名与服务器上的文件名相同。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
我如何强制将本地文件覆盖在git pull
我的本地仓库包含一个文件名文件名与服务器上的文件名相同。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
当前回答
而不是合并git pull
,试试这个:
git fetch --all
随后是:
git reset --hard origin/master
.
其他回答
解决这一问题的另一种办法是,首先将任何未承诺的改动用git stash
然后运行,然后运行
git pull --rebase=interactive -s recursive -X theirs
在互动的重新基础中,你可以改变你所有本地不想要的承诺drop
,这将摆脱他们 并离开你 在远程分支的头部 而不引入合并承诺。
现在你可以跑了git stash apply
如果你有 本地藏的改变 你想带回来。
我刚刚解决了这个问题 自己:
git checkout -b tmp # "tmp" or pick a better name for your local changes branch
git add -A
git commit -m 'tmp'
git pull
git checkout master # Or whatever branch you were on originally
git pull
git diff tmp
最后一个命令给出您本地更改的列表。 继续修改“ tmp” 分支, 直至它可以接受, 然后将它合并为母版 :
git checkout master && git merge tmp
下次,你也许可以用更干净的方式处理这件事, 找到"Git 藏宝分支",虽然藏宝在最初的几例尝试中 可能会给你带来麻烦, 所以首先试验一个非关键项目...
看起来最好的办法是首先做到:
git clean
删除所有未跟踪的文件,然后继续按常规git pull
...
对于那些不喜欢的人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
所需经费:
解决方案 :
获取获取与 a 具有清洁联 联 年 月 日 月 日 月 月 日 月 月 日 月 月 月 日 月 月 日 月 月 日 月 月 月 日 月 月 日 月 月 月 日 月 的 月 月 月 日 月 月 日 月 的 月 月 月 月 日 月 月 月文件 文件和目录目录目录目录忽略忽略. jutignore( )和硬重置重置至来源来源.
git stash --include-untracked
git fetch --all
git clean -fdx
git reset --hard origin/master