如何解决git合并冲突以支持拉取的更改?
我希望从工作树中删除所有冲突的更改,而不必使用gitmergetool处理所有冲突,同时保持所有无冲突的更改。最好是,我想在拉的时候做,而不是事后。
如何解决git合并冲突以支持拉取的更改?
我希望从工作树中删除所有冲突的更改,而不必使用gitmergetool处理所有冲突,同时保持所有无冲突的更改。最好是,我想在拉的时候做,而不是事后。
当前回答
解决了。通过以下简单步骤解决所有冲突。
git fetch && git reset --hard origin/master
git pull -X theirs
git pull origin master
其他回答
在Emacs使用smerge模式中,为了使用我的或他们的冲突标记来解决所有冲突标记,我们可以定义:
(defun aj/smerge-keep-mine-all ()
""
(interactive)
(save-excursion
(beginning-of-buffer)
(while (ignore-errors 'user-error (progn (smerge-next) t))
(smerge-keep-mine))))
(defun aj/smerge-keep-other-all ()
""
(interactive)
(save-excursion
(beginning-of-buffer)
(while (ignore-errors 'user-error (progn (smerge-next) t))
(smerge-keep-other))))
您可以使用递归的“他们的”策略选项:
git merge --strategy-option theirs
来自男子:
ours
This option forces conflicting hunks to be auto-resolved cleanly by
favoring our version. Changes from the other tree that do not
conflict with our side are reflected to the merge result.
This should not be confused with the ours merge strategy, which does
not even look at what the other tree contains at all. It discards
everything the other tree did, declaring our history contains all that
happened in it.
theirs
This is opposite of ours.
注意:正如手册页所说,“我们”的合并策略选项与“我们”合并策略非常不同。
git pull -s recursive -X theirs <remoterepo or other repo>
或者,简单地说,对于默认存储库:
git pull -X theirs
如果你已经处于冲突状态。。。
git checkout --theirs path/to/file
接受远程更改(他们的),如果发生冲突,您将收到以下错误:
fatal: Not possible to fast-forward, aborting.
因此,您可能希望快速地拉动并接受他们的更改:
$ git pull -X theirs --ff
解决了。通过以下简单步骤解决所有冲突。
git fetch && git reset --hard origin/master
git pull -X theirs
git pull origin master