web-dev-qa-db-ja.com

git merge / pullを正しく行う方法:マージが完了していません(MERGE_HEADが存在します)

私はGitの初心者であり、Gitの使用方法を理解するのに苦労しています。私はCVSを使用しているので、Gitについていくらか学習曲線をたどっています。これが私が試したすべてです

これで、PromoServiceImpl.Javaとbuild.sqlの2つのファイルのみを変更しました。ただし、マージに問題がある場合は、「製品」ブランチから変更されました。

表示される残りのファイル(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$ 
13
Smiles in a Jar

ここではいくつかのことが行われています。さまざまな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つのバージョンを維持します マージを保留しているファイルの-yourの変更、プルされた変更、および共通の祖先。プルされたバージョンは一時的にMERGE_HEADに保存されます。

git diff呼び出しで違いを確認できます。この時点で、Gitが自動的に解決できなかった競合を修正する必要があります。修正したら、通常のgit addに続けてgit commitを実行します。このプロセスは、commitコマンドのマニュアルページの例のセクションでも説明されています。

ああ!そして、Addingという名前のファイルがあるようです。 git statusコマンドはで終わることに注意してください

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

これは、Gitにディレクトリの追跡を依頼したときに発生します(git init .を実行したときなど)。それ以降、Gitは指定された場所の変更を監視します。上記は、「Addingというファイルを追加したようです。それについてはよくわかりません(追跡されていません)」と言っています。追加すると、Gitは変更の追跡を開始します(whatが時間の経過とともに変更されたことを通知できます)。

20
Sri Sankaran