ターミナルでプロジェクト ディレクトリをプルしようとすると、次のエラーが表示されます。
harsukh@harsukh-desktop:~/Sites/branch1$ git pull origin master
U app/config/app.php
U app/config/database.php
U app/routes.php
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'.
git が と言うのはなぜですか"Pull is not possible because you have unmerged files"
? また、どうすれば解決できますか?
ベストアンサー1
現在発生しているのは、以前にマージしようとした特定のファイル セットがあり、マージの競合が発生したことです。理想的には、マージの競合が発生した場合は、手動で解決し、 を使用して変更をコミットする必要がありますgit add file.name && git commit -m "removed merge conflicts"
。現在、別のユーザーがリポジトリで問題のファイルを更新し、その変更を共通のアップストリーム リポジトリにプッシュしています。
たまたま、(おそらく)最後のコミットからのマージ競合が解決されなかったため、ファイルが正しくマージされず、そのためファイルにU
( )フラグが立てられています。そのため、 を実行すると、git はエラーをスローします。これは、ファイルの一部のバージョンが正しく解決されていないためです。unmerged
git pull
これを解決するには、問題となっているマージ競合を解決し、変更を追加してコミットしてから、 を実行する必要がありますgit pull
。
問題の再現と解決のサンプル:
# Note: commands below in format `CUURENT_WORKING_DIRECTORY $ command params`
Desktop $ cd test
まず、リポジトリ構造を作成しましょう
test $ mkdir repo && cd repo && git init && touch file && git add file && git commit -m "msg"
repo $ cd .. && git clone repo repo_clone && cd repo_clone
repo_clone $ echo "text2" >> file && git add file && git commit -m "msg" && cd ../repo
repo $ echo "text1" >> file && git add file && git commit -m "msg" && cd ../repo_clone
今、repo_cloneにいます。 を実行するとgit pull
、競合が発生します。
repo_clone $ git pull origin master
remote: Counting objects: 5, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /home/anshulgoyal/Desktop/test/test/repo
* branch master -> FETCH_HEAD
24d5b2e..1a1aa70 master -> origin/master
Auto-merging file
CONFLICT (content): Merge conflict in file
Automatic merge failed; fix conflicts and then commit the result.
クローン内の競合を無視して、元のリポジトリでさらにコミットすると、
repo_clone $ cd ../repo
repo $ echo "text1" >> file && git add file && git commit -m "msg" && cd ../repo_clone
そして、 を実行するとgit pull
、
repo_clone $ git pull
U file
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'.
file
現在、 はマージされていない状態であり、 を実行するとgit status
、同じことが明確にわかることに注意してください。
repo_clone $ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commit each, respectively.
(use "git pull" to merge the remote branch into yours)
You have unmerged paths.
(fix conflicts and run "git commit")
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: file
したがって、これを解決するには、まず、先ほど無視したマージ競合を解決する必要があります。
repo_clone $ vi file
そしてその内容を
text2
text1
text1
そしてそれを追加して変更をコミットします
repo_clone $ git add file && git commit -m "resolved merge conflicts"
[master 39c3ba1] resolved merge conflicts