我有一个存储库,其中我看到了我不理解的行为。
我将发生这种情况的存储库称为“坏存储库”,以下所有序列都在该存储库上运行。
我重置为什么提交并不重要,同样的冲突行为。它报告为冲突的文件似乎是在我重置为的提交中更改的文件。
1) 序列 2 仅发生在“坏存储库”上,相同的命令序列不会在新克隆或任何其他克隆上产生冲突。一个人的 repo 协议(protocol)可能导致这种情况的原因是什么?
2) 为什么在序列 2 中添加任意文件会导致 pull --rebase 冲突?当没有任何更改时,它与序列 1 一样运行良好。
3)基本上,我不明白为什么序列 2 会引起冲突,因为 1、3、4 都工作正常。
.git/config has: [branch "media"] remote = origin merge = refs/heads/media
以下是我正在运行的命令序列和结果:
序列1(复位和 pull )
$ git reset --hard 68a170d HEAD is now at 68a170d Fixes issues with nested attribute sites $ git status # On branch media # Your branch is behind 'origin/media' by 7 commits, and can be fast-forwarded. # nothing to commit (working directory clean) $ git pull --rebase First, rewinding head to replay your work on top of it... Fast-forwarded media to 4c7d9cf046368d4c7770d3b590bf3c1d1f14d480.
序列2(重置添加文件 pull )
$ git reset --hard 68a170d HEAD is now at 68a170d Fixes issues with nested attribute sites $ touch someblahrandomfile $ git add someblahrandomfile $ git commit -m 'blah' [media 9bf2bfb] blah 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 someblahrandomfile $ git status # On branch media # Your branch and 'origin/media' have diverged, # and have 1 and 7 different commit(s) each, respectively. # nothing to commit (working directory clean) $ git pull --rebase First, rewinding head to replay your work on top of it... Applying: Fixed verify methods Using index info to reconstruct a base tree... Falling back to patching base and 3-way merge... Auto-merging app/controllers/jet_controller.rb Auto-merging app/models/claim.rb Auto-merging app/models/site.rb Auto-merging app/models/user.rb CONFLICT (content): Merge conflict in app/models/user.rb Failed to merge in the changes. Patch failed at 0001 Fixed verify methods When you have resolved this problem run "git rebase --continue". If you would prefer to skip this patch, instead run "git rebase --skip". To restore the original branch and stop rebasing run "git rebase --abort".
序列 3(使用额外参数重置添加文件 pull )
$ git reset --hard 68a170d HEAD is now at 68a170d Fixes issues with nested attribute sites $ touch zz $ git add zz $ git commit -m 'blah4' [media c79214d] blah4 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 zz $ git status # On branch media # Your branch and 'origin/media' have diverged, # and have 1 and 7 different commit(s) each, respectively. # nothing to commit (working directory clean) $ git pull --rebase -- origin media * branch media -> FETCH_HEAD First, rewinding head to replay your work on top of it... Applying: blah4
序列 4(重置和 rebase )
$ git reset --hard 68a170d HEAD is now at 68a170d Fixes issues with nested attribute sites $ touch vv $ git add vv $ git commit -m 'blah7' [media 6c3f42b] blah7 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 vv $ git status # On branch media # Your branch and 'origin/media' have diverged, # and have 1 and 7 different commit(s) each, respectively. # nothing to commit (working directory clean) $ git rebase origin/media First, rewinding head to replay your work on top of it... Applying: blah7
其他信息
a) 错误的存储库位于 Mac osx 10.6.4 上
b) Git 1.7.1
c)
color.branch=auto color.diff=auto color.status=auto color.branch.current=yellow reverse color.branch.local=yellow color.branch.remote=green color.diff.meta=yellow bold color.diff.frag=magenta bold color.diff.old=red bold color.diff.new=green bold color.status.added=yellow color.status.changed=green color.status.untracked=cyan merge.tool=opendiff mergetool.tool=opendiff difftool.difftool=opendiff gui.recentrepo=/git/MYREPO user.name=USER user.email=EMAIL alias.wtf=git-wtf alias.lg=log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true core.ignorecase=true remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* remote.origin.url=URL branch.master.remote=origin branch.master.merge=refs/heads/master branch.media.remote=origin branch.media.merge=refs/heads/media
更新 2(第一组 >>> 应该指向另一个方向,但无法正确显示)
$ git diff diff --cc app/models/user.rb index e1c31e2,f4923e6..0000000 --- a/app/models/user.rb +++ b/app/models/user.rb has_many :coupon_codes accepts_nested_attributes_for :coupon_codes >>>>>>> HEAD ======= has_many :sites, :dependent => :destroy accepts_nested_attributes_for :sites, :allow_destroy => true >>>>>>> Fixed verify methods
最佳答案
你为什么要 rebase ?我认为在上面的场景中没有必要使用它。 rebase 重写历史。
场景1:
Your branch is behind 'origin/media' by 7 commits, and can be fast-forwarded.
快进吧! git merge origin/media
或者简单地git pull
, --rebase
太过分了,你没有什么可应用的。
你在这里:
A1
来源/媒体在这里:
A1-A2-A3-A4-A5-A6-A7-A8
(等等)它是线性的,只是通过 merge 快进。
快进移动指针。 rebase 存储更改(如果它说可以,则您没有更改),然后重新应用您的提交作为新提交,重写历史记录。但你没有,所以这只是浪费精力。
场景 2:
再说一遍,你为什么要 rebase ? rebase 用新的提交重写历史。如果您不需要重新排序历史记录,则不要重新排序历史记录
场景 2 会给您带来问题,因为 git pull --rebase
将使用默认远程( origin master
)的默认分支重新设置当前分支的基础。在配置中,您有 branch.media.merge
设置,但不是 branch.media.rebase
。因此,git pull
(默认运行 merge )将从 origin media
中提取,但是git pull --rebase
将从origin master
pull (默认)。这也解释了为什么场景 3 和 4 有效:您明确告诉它要从哪个分支/源进行 rebase 。
来自 man git-config
:
branch.<name>.rebase
When true, rebase the branch <name> on top of the fetched branch, instead of merging the default branch from the default remote when "git pull" is run. NOTE: this is a possibly dangerous operation; do not use it unless you understand the implications (see git- rebase(1) for details).
关于Git 与不相关文件上的 pull --rebase 发生冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3295907/