我如何忽略“git pull"上关于我的本地更改将被合并覆盖的错误? [英] How do I ignore an error on 'git pull' about my local changes would be overwritten by merge?
问题描述
如何在 Git pull 上忽略以下错误信息?
How do I ignore the following error message on Git pull?
您对以下文件的本地更改将被合并覆盖
Your local changes to the following files would be overwritten by merge
如果我想要覆盖它们怎么办?
What if I want to overwrite them?
我尝试过诸如 git pull -f
之类的东西,但没有任何效果.
I've tried things like git pull -f
, but nothing works.
明确地说,我只想覆盖特定的更改,而不是全部.
To be clear, I only want to overwrite specific changes, not everything.
推荐答案
如果您想从您的工作副本中删除所有本地更改(包括 git 未跟踪的文件),只需将它们隐藏起来:
If you want remove all local changes - including files that are untracked by git - from your working copy, simply stash them:
git stash push --include-untracked
如果你不再需要它们,你现在可以放下那个藏匿处:
If you don't need them anymore, you now can drop that stash:
git stash drop
如果您不想隐藏已经上演的更改 - 例如使用 git add
- 然后添加选项 --keep-index
.但是请注意,如果这些阶段性更改与来自上游的更改发生冲突,这仍然会阻止合并.
If you don't want to stash changes that you already staged - e.g. with git add
- then add the option --keep-index
. Note however, that this will still prevent merging if those staged changes collide with the ones from upstream.
如果您只想覆盖本地更改的特定部分,有两种可能:
If you want to overwrite only specific parts of your local changes, there are two possibilities:
提交您不想覆盖的所有内容,其余部分使用上述方法.
Commit everything you don't want to overwrite and use the method above for the rest.
对您希望覆盖的更改使用 git checkout path/to/file/to/revert
.确保文件没有通过 git reset HEAD path/to/file/to/revert
暂存.
Use git checkout path/to/file/to/revert
for the changes you wish to overwrite. Make sure that file is not staged via git reset HEAD path/to/file/to/revert
.
这篇关于我如何忽略“git pull"上关于我的本地更改将被合并覆盖的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!