我如何强制将本地文件覆盖在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
其他回答
我刚刚解决了这个问题 自己:
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
...
尽管最初提出这个问题,但顶尖的答案会给有类似问题的人造成问题,但不想失去本地文件。例如,见Al-Punk和CrizCraig的评论。
以下版本对临时事务组(临时事务组)进行本地变更(临时事务组)tmp
检查原始分支(我假设master
)和合并更新。您可以用stash
,但我发现通常更容易使用分支/合并方法。
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
我们假设其它存储库是origin master
.
对于那些不喜欢的人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
警告:
对已跟踪文件的本地更改将丢失 。 @ info: whatsthis
任何本地文件否吉特追踪到的不会受到影响。
第一,更新所有origin/<branch>
最晚的 refs :
git fetch --all # if this doesn't work try `git pull -f` (see comments)
备份当前分支( 例如 )master
):
git branch backup-master
跳转到最新承诺origin/master
并检出这些文件 :
git reset --hard origin/master
git fetch
从远程下载最新数据,不试图合并或重标任何内容。
git reset
将主分支重置为您刚获取的 。--hard
选项选项 更改工作树中的全部文件以匹配文件origin/master
.
[*]值得指出的是,通过从master
在重设前:
git checkout master
git branch new-branch-to-save-current-commits
git fetch --all # if this doesn't work try `git pull -f` (see comments)
git reset --hard origin/master
在那之后,一切旧事,将永居其中;new-branch-to-save-current-commits
.
将丢失未承诺的更改( 即使是第 阶段的更改) 。 请确保隐藏并承诺您需要的一切 。 为此您可以运行以下操作 :
git stash
然后重新应用这些未承诺的修改:
git stash pop