왜 자식이 "파일을 병합 해제했기 때문에 풀을 사용할 수 없습니다"라고 표시합니까?
터미널에서 프로젝트 디렉토리를 가져 오려고하면 다음 오류가 표시됩니다.
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'.
왜 자식이라고 말하고 "Pull is not possible because you have unmerged files"
어떻게 해결할 수 있습니까?
현재 일어나고있는 것은 이전에 병합을 시도했지만 병합 충돌을 일으킨 특정 파일 세트가 있다는 것입니다. 이상적으로, 병합 충돌이 발생하면 수동으로 해결하고를 사용하여 변경 사항을 커밋해야합니다 git add file.name && git commit -m "removed merge conflicts"
. 이제 다른 사용자가 자신의 저장소에서 문제의 파일을 업데이트하고 변경 사항을 공통 업스트림 저장소로 푸시했습니다.
병합이 마지막 커밋과 충돌했을 가능성이 크지 않으므로 파일이 제대로 병합되지 않아 파일의 U
( unmerged
) 플래그가 발생합니다. 따라서 이제는.을 수행 할 때 git pull
git에서 오류가 발생합니다. 파일의 일부 버전이 올바르게 해결되지 않았기 때문입니다.
이 문제를 해결하려면 문제의 병합 충돌을 해결하고 변경 사항을 추가 및 커밋해야합니다 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'.
Note that the file
now is in an unmerged state and if we do a git status
, we can clearly see the same:
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
So, to resolve this, we first need to resolve the merge conflict we ignored earlier
repo_clone $ vi file
and set its contents to
text2
text1
text1
and then add it and commit the changes
repo_clone $ git add file && git commit -m "resolved merge conflicts"
[master 39c3ba1] resolved merge conflicts
You are attempting to add one more new commits into your local branch while your working directory is not clean. As a result, Git is refusing to do the pull. Consider the following diagrams to better visualize the scenario:
remote: A <- B <- C <- D
local: A <- B*
(*indicates that you have several files which have been modified but not committed.)
There are two options for dealing with this situation. You can either discard the changes in your files, or retain them.
Option one: Throw away the changes
You can either use git checkout
for each unmerged file, or you can use git reset --hard HEAD
to reset all files in your branch to HEAD. By the way, HEAD in your local branch is B, without an asterisk. If you choose this option, the diagram becomes:
remote: A <- B <- C <- D
local: A <- B
Now when you pull, you can fast-forward your branch with the changes from master. After pulling, you branch would look like master:
local: A <- B <- C <- D
Option two: Retain the changes
If you want to keep the changes, you will first want to resolve any merge conflicts in each of the files. You can open each file in your IDE and look for the following symbols:
<<<<<<< HEAD
// your version of the code
=======
// the remote's version of the code
>>>>>>>
Git is presenting you with two versions of code. The code contained within the HEAD markers is the version from your current local branch. The other version is what is coming from the remote. Once you have chosen a version of the code (and removed the other code along with the markers), you can add each file to your staging area by typing git add
. The final step is to commit your result by typing git commit -m
with an appropriate message. At this point, our diagram looks like this:
remote: A <- B <- C <- D
local: A <- B <- C'
Here I have labelled the commit we just made as C' because it is different from the commit C on the remote. Now, if you try to pull you will get a non-fast forward error. Git cannot play the changes in remote on your branch, because both your branch and the remote have diverged from the common ancestor commit B. At this point, if you want to pull you can either do another git merge
, or git rebase
your branch on the remote.
Getting a mastery of Git requires being able to understand and manipulate uni-directional linked lists. I hope this explanation will get you thinking in the right direction about using Git.
Theres a simple solution to it. But for that you will first need to learn the following
vimdiff
To remove conficts, you can use
git mergetool
The above command basically opens local file, mixed file, remote file (3 files in total), for each conflicted file. The local & remote files are just for your reference, and using them you can choose what to include (or not) in the mixed file. And just save and quit the file.
If you dont want to merge the changes and still want to update your local then run:
git reset --hard HEAD
This will reset your local with HEAD and then pull your remote using git pull.
If you've already committed your merge locally (but haven't pushed to remote yet), and want to revert it as well:
git reset --hard HEAD~1
If you want to pull down a remote branch to run locally (say for reviewing or testing purposes), and when you $ git pull
you get local merge conflicts:
$ git checkout REMOTE-BRANCH
$ git pull (you get local merge conflicts)
$ git reset --hard HEAD (discards local conflicts, and resets to remote branch HEAD)
$ git pull (now get remote branch updates without local conflicts)
You have some files locally that need to be merged before you can pull. You could checkout the files and then pull to overwrite your local files.
git checkout app/config/app.php app/config/database.php app/routes.php
git pull origin master
There was same issue with me
In my case, steps are as below-
- Removed all file which was being start with U (unmerged) symbol. as-
U project/app/pages/file1/file.ts
U project/www/assets/file1/file-name.html
- Pull code from master
$ git pull origin master
- Checked for status
$ git status
Here is the message which It appeared-
and have 2 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 ..." to mark resolution)
both modified: project/app/pages/file1/file.ts
both modified: project/www/assets/file1/file-name.html
- Added all new changes -
$ git add project/app/pages/file1/file.ts
project/www/assets/file1/file-name.html
- Commit changes on head-
$ git commit -am "resolved conflict of the app."
- Pushed the code -
$ git push origin master
Which turn may issue resolved with this image -
When a merge conflict occurs , you can open individual file. You will get "<<<<<<< or >>>>>>>" symbols. These refer to your changes and the changes present on remote. You can manually edit the part that is requires. after that save the file and then do : git add
The merge conflicts will be resolved.
Just run this command:
git reset --hard
'Programing' 카테고리의 다른 글
Bash를 사용하는 가장 좋아하는 명령 줄 트릭은 무엇입니까? (0) | 2020.06.05 |
---|---|
build.gradle 파일에 주석을 작성하는 구문은 무엇입니까? (0) | 2020.06.04 |
원격 레지스트리에 Docker 이미지의 모든 태그를 나열하는 방법은 무엇입니까? (0) | 2020.06.04 |
UIViewController viewDidLoad 대 viewWillAppear : 적절한 분업은 무엇입니까? (0) | 2020.06.04 |
기본 ES6 약속에서 Bluebird Promise.finally에 해당하는 것은 무엇입니까? (0) | 2020.06.04 |