Как правильно выполнить git merge / pull: вы не завершили свое слияние (MERGE_HEAD существует) - PullRequest
13 голосов
/ 14 декабря 2011

Я новичок в Git и не могу понять, как использовать Git.Я использовал CVS, поэтому прошёл некоторую кривую обучения Git.Вот что все, что я пытался

Теперь я изменил только два файла PromoServiceImpl.java и build.sql.Однако возникли проблемы с слиянием изменились из "продукта" отрасли.

Остальные файлы, которые вы видите (например, ApiServiceImpl.java и т. Д.), Являются изменениями других пользователей, но я не уверен, что приведенное здесь представление говорит о том, что я их изменил.Возможно, он был объединен во время более ранних команд извлечения, и теперь он ожидает, что я передам их ??

Независимо от того, какой поток команд я выполняю (даже после некоторого поиска в Google), я вижу следующую ошибку:

Вы не завершили свое слияние (MERGE_HEAD существует) Пожалуйста, передайте ваши изменения, прежде чем вы сможете слить.

Вот последовательность команд, которые я выполнил и вывел (пытался это сделатьдовольно, вставляя новые строки для всех, чтобы прочитать).Также эта ошибка возвращается даже после повторного получения изменений из хранилища, поэтому я уверен, что я делаю что-то не так, а не какую-то проблему с git.

kamal@kamal-Lenovo-G470:~/git/TryGit$ gs
# On branch product
# Your branch is ahead of 'origin/product' by 1 commit.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   TryGitServices/src/main/java/com/TryGit/services/promo/impl/PromoServiceImpl.java
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   Adding
no changes added to commit (use "git add" and/or "git commit -a")


kamal@kamal-Lenovo-G470:~/git/TryGit$ git pull origin product
From ssh://192.168.2.251/TryGit
 * branch            product    -> FETCH_HEAD
Auto-merging TryGitResources/build/build.sql
CONFLICT (content): Merge conflict in TryGitResources/build/build.sql
Automatic merge failed; fix conflicts and then commit the result.


kamal@kamal-Lenovo-G470:~/git/TryGit$ gs
# On branch product
# Your branch is ahead of 'origin/product' by 1 commit.
#
# Changes to be committed:
#
#   modified:   TryGitCore/src/main/java/com/TryGit/core/api/binding.xml
#   modified:   TryGitServices/src/main/java/com/TryGit/services/api/impl/ApiServiceImpl.java
#   modified:   TryGitServices/src/main/java/com/TryGit/services/common/impl/StartupServiceImpl.java
#   modified:   TryGitWeb/src/main/webapp/WEB-INF/wsdl/TryGit.wsdl
#   modified:   TryGitWeb/src/main/webapp/static/css/TryGit/homeDeal.css
#   modified:   TryGitWeb/src/main/webapp/static/css/TryGit/TryGit.css
#   modified:   TryGitWeb/src/main/webapp/static/img/TryGit/sprite/TryGit.png
#   modified:   TryGitWeb/src/main/webapp/views/admin/createPromoCode.jsp
#   modified:   TryGitWeb/src/main/webapp/views/admin/product/productAdmin.jsp
#   modified:   TryGitWeb/src/main/webapp/views/deal/homePage.jsp

#
# Unmerged paths:
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#   both modified:      TryGitResources/build/build.sql
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   TryGitServices/src/main/java/com/TryGit/services/promo/impl/PromoServiceImpl.java
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   Adding


kamal@kamal-Lenovo-G470:~/git/TryGit$ git reset TryGitResources/build/build.sql
Unstaged changes after reset:
M   TryGitResources/build/build.sql
M   TryGitServices/src/main/java/com/TryGit/services/promo/impl/PromoServiceImpl.java
kamal@kamal-Lenovo-G470:~/git/TryGit$ gs
# On branch product
# Your branch is ahead of 'origin/product' by 1 commit.
#
# Changes to be committed:
#
#   modified:   TryGitCore/src/main/java/com/TryGit/core/api/binding.xml
#   modified:   TryGitResources/build/build.sql
#   modified:   TryGitServices/src/main/java/com/TryGit/services/api/impl/ApiServiceImpl.java
#   modified:   TryGitServices/src/main/java/com/TryGit/services/common/impl/StartupServiceImpl.java
#   modified:   TryGitWeb/src/main/webapp/WEB-INF/wsdl/TryGit.wsdl
#   modified:   TryGitWeb/src/main/webapp/static/css/TryGit/homeDeal.css
#   modified:   TryGitWeb/src/main/webapp/static/css/TryGit/TryGit.css
#   modified:   TryGitWeb/src/main/webapp/static/img/TryGit/sprite/TryGit.png
#   modified:   TryGitWeb/src/main/webapp/views/admin/createPromoCode.jsp
#   modified:   TryGitWeb/src/main/webapp/views/admin/product/productAdmin.jsp
#   modified:   TryGitWeb/src/main/webapp/views/deal/homePage.jsp
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   TryGitResources/build/build.sql
#   modified:   TryGitServices/src/main/java/com/TryGit/services/promo/impl/PromoServiceImpl.java
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   Adding


kamal@kamal-Lenovo-G470:~/git/TryGit$ git stash
Saved working directory and index state WIP on product: b8bb080 changing build.sql for RBT task
HEAD is now at b8bb080 changing build.sql for RBT task


kamal@kamal-Lenovo-G470:~/git/TryGit$ gs
# On branch product
# Your branch is ahead of 'origin/product' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   Adding
nothing added to commit but untracked files present (use "git add" to track)


kamal@kamal-Lenovo-G470:~/git/TryGit$ git reset Adding


kamal@kamal-Lenovo-G470:~/git/TryGit$ git reset Adding


kamal@kamal-Lenovo-G470:~/git/TryGit$ gs
# On branch product
# Your branch is ahead of 'origin/product' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   Adding
nothing added to commit but untracked files present (use "git add" to track)

kamal@kamal-Lenovo-G470:~/git/TryGit$ git rm Adding
fatal: pathspec 'Adding' did not match any files

kamal@kamal-Lenovo-G470:~/git/TryGit$ man git rm

kamal@kamal-Lenovo-G470:~/git/TryGit$ git rm Adding
fatal: pathspec 'Adding' did not match any files

kamal@kamal-Lenovo-G470:~/git/TryGit$ gs
# On branch product
# Your branch is ahead of 'origin/product' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   Adding
nothing added to commit but untracked files present (use "git add" to track)

kamal@kamal-Lenovo-G470:~/git/TryGit$ git pull origin product
remote: Counting objects: 566, done.
remote: Compressing objects: 100% (316/316), done.
remote: Total 386 (delta 207), reused 0 (delta 0)
Receiving objects: 100% (386/386), 203.81 KiB, done.
Resolving deltas: 100% (207/207), completed with 56 local objects.
From ssh://192.168.2.251/TryGit
 * branch            product    -> FETCH_HEAD
Auto-merging TryGitResources/build/build.sql
CONFLICT (content): Merge conflict in TryGitResources/build/build.sql
Automatic merge failed; fix conflicts and then commit the result.

kamal@kamal-Lenovo-G470:~/git/TryGit$ git pull origin product
M   TryGitCore/src/main/java/com/TryGit/core/api/binding.xml
U   TryGitResources/build/build.sql
M   TryGitServices/src/main/java/com/TryGit/services/api/impl/ApiServiceImpl.java
M   TryGitServices/src/main/java/com/TryGit/services/common/impl/StartupServiceImpl.java
M   TryGitWeb/src/main/webapp/WEB-INF/wsdl/TryGit.wsdl
M   TryGitWeb/src/main/webapp/static/css/TryGit/homeDeal.css
M   TryGitWeb/src/main/webapp/static/css/TryGit/TryGit.css
M   TryGitWeb/src/main/webapp/static/img/TryGit/sprite/TryGit.png
M   TryGitWeb/src/main/webapp/views/admin/createPromoCode.jsp
M   TryGitWeb/src/main/webapp/views/admin/product/productAdmin.jsp
M   TryGitWeb/src/main/webapp/views/deal/homePage.jsp
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.

kamal@kamal-Lenovo-G470:~/git/TryGit$ git add TryGitResources/build/build.sql
kamal@kamal-Lenovo-G470:~/git/TryGit$ git pull origin product
You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you can merge.
kamal@kamal-Lenovo-G470:~/git/TryGit$ gs
# On branch product
# Your branch is ahead of 'origin/product' by 1 commit.
#
# Changes to be committed:
#
#   modified:   TryGitCore/src/main/java/com/TryGit/core/api/binding.xml
#   modified:   TryGitResources/build/build.sql
#   modified:   TryGitServices/src/main/java/com/TryGit/services/api/impl/ApiServiceImpl.java
#   modified:   TryGitServices/src/main/java/com/TryGit/services/common/impl/StartupServiceImpl.java
#   modified:   TryGitWeb/src/main/webapp/WEB-INF/wsdl/TryGit.wsdl
#   modified:   TryGitWeb/src/main/webapp/static/css/TryGit/homeDeal.css
#   modified:   TryGitWeb/src/main/webapp/static/css/TryGit/TryGit.css
#   modified:   TryGitWeb/src/main/webapp/static/img/TryGit/sprite/TryGit.png
#   modified:   TryGitWeb/src/main/webapp/views/admin/createPromoCode.jsp
#   modified:   TryGitWeb/src/main/webapp/views/admin/product/productAdmin.jsp
#   modified:   TryGitWeb/src/main/webapp/views/deal/homePage.jsp

#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   Adding

kamal@kamal-Lenovo-G470:~/git/TryGit$ git pull origin product
You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you can merge.

kamal@kamal-Lenovo-G470:~/git/TryGit$ 

1 Ответ

20 голосов
/ 14 декабря 2011

Здесь происходит несколько вещей. Это помогает понять, что происходит, когда вы выполняете различные команды Git.

Команда pull (как в git pull) приводит к a fetch с последующим merge. Итак, когда вы сделали pull

kamal@kamal-Lenovo-G470:~/git/TryGit$ git pull origin product

Git попытался получить изменения из удаленного репозитория по умолчанию

From ssh://192.168.2.251/TryGit
 * branch            product    -> FETCH_HEAD

и объединить их.

Auto-merging TryGitResources/build/build.sql

При этом столкнулся с конфликтом

CONFLICT (content): Merge conflict in TryGitResources/build/build.sql
Automatic merge failed; fix conflicts and then commit the result.

Git поддерживает эти 3 версии файла в ожидании слияния - ваши изменения, внесенные изменения и общий предок. Полученная версия временно сохраняется в MERGE_HEAD.

Вы можете увидеть различия с помощью вызова git diff. На этом этапе вам нужно исправить конфликты, которые Git не смог разрешить автоматически. Как только вы исправите это, просто выполните обычный git add, а затем git commit. Этот процесс также объясняется в разделе примеров на странице руководства для команды commit.

Oh! И, похоже, у вас есть файл с именем Adding. Обратите внимание, что команда git status заканчивается на

# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   Adding

Это происходит, когда вы просите Git отслеживать каталог (например, когда вы это сделали git init .). С этого момента Git отслеживает изменения в указанном месте. Выше сказано: «Я вижу, что вы добавили файл с именем« Добавление ». Я не знаю о нем больше (он не отслежен)». Как только вы добавите его, Git начнет отслеживать изменения (может сообщить вам , что изменилось с течением времени).

...