Git与不相关文件上的pull --rebase冲突

时间:2010-07-21 02:37:04

标签: git version-control dvcs

我有一个回购,我看到的行为是我不理解的。

我将这个回复报告称为“坏回购”,所有以下序列都在该回复上运行。

我重置的提交无关紧要,相同的冲突行为。它报告为冲突的文件似乎是我重置为的提交中已更改的文件。

1)序列2仅发生在'坏回购'上,相同的命令序列导致新鲜克隆或其他任何人没有冲突。什么是一个人回购可能导致这个?

2)为什么在序列2中添加任意文件会导致pull -rebase发生冲突?当没有变化时,它在序列1中工作正常。

3)基本上,我不明白为什么序列2会引起冲突,因为1,3,4都可以正常工作。

.git/config has:

[branch "media"]
    remote = origin
    merge = refs/heads/media

以下是我正在运行的命令序列和结果:

序列1(重置和拉动)

$ 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(重置添加文件拉)

$ 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(使用额外的参数重置添加文件)

$ 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(重置和重组)

$ 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

1 个答案:

答案 0 :(得分:3)

你为什么要变基?我认为上面的场景中没有必要使用它。重新重写历史记录

情景1:

  

你的分支在7个提交后面是'origin / media',可以快进。

如此快速前进! git merge origin/media或仅git pull--rebase过度,您无需应用任何内容

你在这里: A1

origin / media在这里: A1-A2-A3-A4-A5-A6-A7-A8(依此类推)它是线性的,只需快进即可进行合并。

快进移动指针。重新发布stashes更改(如果它表明你可以ff,则没有),然后重新提交你的提交作为新提交,重写历史记录。但是你没有,所以这只是浪费在跳过篮球。

情景2:

再次,你为什么要变基础?使用新提交重新重写历史记录。如果您不需要重新排序历史记录,请不要重新排序历史记录

方案2会给您带来问题,因为git pull --rebase将使用默认远程(origin master)的默认分支重新绑定当前分支。在配置中,您设置了branch.media.merge,但没有设置branch.media.rebase。因此,git pull(默认情况下会运行合并)将从origin media拉出,但git pull --rebase将从origin master(默认值)拉出。这也解释了为什么场景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).