git - 如何正确执行 git merge/pull : You have not concluded your merge (MERGE_HEAD exists)

标签 git merge git-pull

我是 Git 的新手,不太了解如何使用 Git。我一直在使用 CVS,因此经历了一些 Git 的学习曲线。这是我所有的尝试

现在我只更改了两个文件 PromoServiceImpl.java 和 build.sql。但是, merge 从“产品”分支更改时遇到麻烦。

您看到的剩余文件(如 ApiServiceImpl.java 等)是其他用户所做的更改,但我不确定此处的表示是否表明我已更改它们。可能它在早期的 pull 命令中被 merge 了,现在它希望我提交它们??

无论我遵循什么命令流程(即使经过一些 Google 搜索)我都会看到以下错误:

You have not concluded your merge (MERGE_HEAD exists) Please, commit your changes before you can merge.

这是我遵循并输出的命令序列(试图通过插入新行让每个人都能阅读来让它更漂亮)。即使在重新从存储库中进行更改后,此错误也会再次出现,因此我确定我做错了什么而不是 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$ 

最佳答案

这里发生了几件事。它有助于理解发出各种 Git 命令时会发生什么。

pull 命令(如 git pull)results in fetch 后跟 merge。所以当你做了一个pull

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

Git 尝试从默认的远程存储库中 pull 更改

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

并将它们 merge 。

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 maintains this 3 versions等待 merge 的文件的数量 -- 您的 更改、引入的更改和共同的祖先。 pull 入的版本暂时 stash 在MERGE_HEAD中。

您可以通过 git diff 调用查看差异。此时您需要修复 Git 无法自动解决的冲突。修复后,只需执行通常的 git add,然后执行 git commitcommit 命令的手册页的示例部分也解释了此过程。

哦!看起来您有一个名为 Adding文件。请注意,git status 命令以

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

当您要求 Git 跟踪目录时(例如当您执行 git init . 时),就会发生这种情况。从此 Git 监控指定位置的变化。上面是说“我看到你已经添加了一个名为 Adding 的文件。我对它了解不多(它是未跟踪的)。”一旦你添加它,Git 就会开始跟踪变化(可以告诉你什么随着时间的推移发生了变化)。

关于git - 如何正确执行 git merge/pull : You have not concluded your merge (MERGE_HEAD exists),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8505289/

相关文章:

git - 在同一个分支上工作,如何在不丢失更改的情况下进行 pull ?

git - 使用 git pull 在不 merge 的情况下跟踪远程分支

Git 工作流 : Rebasing Published/Shared Branches

git - 如何让 git log 显示相对于当前目录的文件路径?

mysql - 如何进行sql连接/合并

python - 如何使用列的值将 2 个 numpy ndarray 合并到 ndarray 上?

Git Pull 与 Git fetch 哪个更好?

git - 了解基本的 git 钩子(Hook)

regex - Git - 不包括{}的颜色词

r - 在替换 NA 时合并组中的行