如何解决git合并冲突以支持拉取的更改?
我希望从工作树中删除所有冲突的更改,而不必使用gitmergetool处理所有冲突,同时保持所有无冲突的更改。最好是,我想在拉的时候做,而不是事后。
如何解决git合并冲突以支持拉取的更改?
我希望从工作树中删除所有冲突的更改,而不必使用gitmergetool处理所有冲突,同时保持所有无冲突的更改。最好是,我想在拉的时候做,而不是事后。
当前回答
解决了。通过以下简单步骤解决所有冲突。
git fetch && git reset --hard origin/master
git pull -X theirs
git pull origin master
其他回答
要解决与特定分支中版本的所有冲突,请执行以下操作:
git diff --name-only --diff-filter=U | xargs git checkout ${branchName}
因此,如果您已经处于合并状态,并且希望保留冲突文件的主版本:
git diff --name-only --diff-filter=U | xargs git checkout master
如果您已经处于冲突状态,并且不想逐个签出路径。你可以试试
git merge --abort
git pull -X theirs
VS代码(集成Git)IDE用户:
如果要接受冲突文件中的所有传入更改,请执行以下步骤。
1. Go to command palette - Ctrl + Shift + P
2. Select the option - Merge Conflict: Accept All Incoming
类似地,您可以使用其他选项,如“全部接受”、“全部接受当前”等。,
在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 cherry-pick 1023e24
error: could not apply 1023e24... [Commit Message]
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
现在,您查看了冲突的文件,并且确实不想保留更改。在我上面的例子中,文件仅在IDE自动添加的新行上发生冲突。要撤消更改并接受其更改,最简单的方法是:
git checkout --theirs path/to/the/conflicted_file.php
git add path/to/the/conflicted_file.php
与此相反(用您的版本覆盖传入的版本)是
git checkout --ours path/to/the/conflicted_file.php
git add path/to/the/conflicted_file.php
令人惊讶的是,我在网上很难找到这个答案。