Git конфликтует с pull --rebase для несвязанного файла - PullRequest
2 голосов
/ 21 июля 2010

У меня есть репо, где я вижу поведение, которое не понимаю.

Я буду называть репо, на котором это происходит, «плохим репо», все последующие последовательности были запущены на этом.

Неважно, к какому коммиту я возвращаюсь, такое же противоречивое поведение. Файлы, которые он сообщает как конфликтующие, похоже, были изменены в коммите, который я сбросил.

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

Дополнительная информация

а) Плохое репо на Mac OSX 10.6.4
б) Git 1.7.1
в)

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 Ответ

3 голосов
/ 07 января 2011

Почему ты перебазируешь?Я не вижу необходимости в ваших сценариях выше использовать его.Rebase переписывает историю .

Сценарий 1:

Ваша ветвь отстает от 'origin / media' на 7 коммитов и может быть перемотана вперед.

Столь быстрая перемотка впередЭто!git merge origin/media или просто git pull, --rebase излишне, вам нечего применить .

Вы здесь: A1

Происхождение / носитель здесь: A1-A2-A3-A4-A5-A6-A7-A8 (и т. Д.), Он линейный, просто ускоренная перемотка вперед с объединением.

Перемотка вперед перемещает указатель .Перебазирование тайников изменений (которых у вас нет, если он говорит, что вы можете 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 работают: вы явно указываете, из какой ветки / источника делать ребазинг.

С 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).
...