힘내 rebase : 갈등은 진행을 막는다
어제 마스터에서 만든 자식 분기 (v4라고 함)가 있습니다. v4에 들어가기 위해 master에 몇 가지 변경 사항이있었습니다. 따라서 v4에서는 마스터에서 리베이스를 시도했지만 한 파일은 버전 번호가 포함 된 한 줄 텍스트 파일을 계속 조입니다. 이 파일은 app/views/common/version.txt
rebasing 전에 다음 텍스트를 포함합니다.
v1.4-alpha-02
내가하고있는 일은 다음과 같습니다.
> git rebase master
First, rewinding head to replay your work on top of it...
Applying: new version, new branch
error: patch failed: app/views/common/version.txt:1
error: app/views/common/version.txt: patch does not apply
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging app/views/common/version.txt
CONFLICT (content): Merge conflict in app/views/common/version.txt
Failed to merge in the changes.
Patch failed at 0001 new version, new branch
When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".
은 version.txt
이제 다음과 같습니다 :
<<<<<<< HEAD:app/views/common/version.txt
v1.4-alpha-02
=======
v1.4-alpha-01
>>>>>>> new version, new branch:app/views/common/version.txt
그래서 나는 그것을 정리하고 이제 다음과 같이 보입니다 :
v1.4-alpha-02
그런 다음 계속하려고했습니다. 처음에는 커밋을 시도합니다.
> git commit -a -m "merged"
# Not currently on any branch.
nothing to commit (working directory clean)
운이 없다. 그래서 파일을 추가하려고했습니다.
git add app/views/common/version.txt
응답 없음. 좋은 소식은 없다고 생각합니다. 그래서 계속하려고합니다.
> git rebase --continue
Applying: new version, new branch
No changes - did you forget to use 'git add'?
When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".
이 시점에서 빙글 빙글 돌고 책상에서 머리를 두드리고 있습니다.
무슨 일이야? 내가 뭘 잘못하고 있죠? 누구든지 나를 똑바로 설 수 있습니까?
편집-unutbu
제안한대로 파일을 변경했는데 같은 오류가 발생합니다.
> git rebase master
First, rewinding head to replay your work on top of it...
Applying: new version, new branch
error: patch failed: app/views/common/version.txt:1
error: app/views/common/version.txt: patch does not apply
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging app/views/common/version.txt
CONFLICT (content): Merge conflict in app/views/common/version.txt
Failed to merge in the changes.
Patch failed at 0001 new version, new branch
When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".
rebase와 비슷한 문제가 발생했습니다. 내 커밋 중 하나가 파일 만 변경했기 때문에 문제가 발생했으며 해결 할 때이 커밋에 도입 된 변경 사항을 버렸습니다. 해당 커밋 ( git rebase --skip
) 을 건너 뛰면 문제를 해결할 수있었습니다 .
테스트 저장소에서이 문제를 재현 할 수 있습니다. 먼저 저장소를 작성하십시오.
$ mkdir failing-merge
$ cd failing-merge
$ git init
Initialized empty Git repository in $HOME/failing-merge/.git/
그런 다음 version.txt
마스터 의 원본 내용을 커밋하십시오 .
$ echo v1.4-alpha-02 > version.txt
$ git add version.txt
$ git commit -m initial
[master (root-commit) 2eef0a5] initial
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 version.txt
만들기 v4
분기 및 내용을 변경 version.txt
.
$ git checkout -b v4
Switched to a new branch 'v4'
$ echo v1.4-alpha-03 > version.txt
$ git add version.txt
$ git commit -m v4
[v4 1ef8c9b] v4
1 files changed, 1 insertions(+), 1 deletions(-)
rebase 중에 충돌이 발생하도록 master
컨텐츠로 돌아가서 변경하십시오 version.txt
.
$ git checkout master
Switched to branch 'master'
$ echo v1.4-alpha-04 > version.txt
$ git add version.txt
$ git commit -m master
[master 7313eb3] master
1 files changed, 1 insertions(+), 1 deletions(-)
Switch back to v4
branch and try to rebase. It fails with a conflit in version.txt
as planned.
$ git checkout v4
Switched to branch 'v4'
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: v4
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging version.txt
CONFLICT (content): Merge conflict in version.txt
Recorded preimage for 'version.txt'
Failed to merge in the changes.
Patch failed at 0001 v4
When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".
$ cat version.txt
<<<<<<< HEAD
v1.4-alpha-04
=======
v1.4-alpha-03
>>>>>>> v4
We resolve the conflict by selecting the master
content of version.txt
. We add the file and try to continue our rebase.
$ echo v1.4-alpha-04 > version.txt
$ git add version.txt
$ git rebase --continue
Applying: v4
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.
When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".
It fails ! Let's see what changes git
think there is in our repository.
$ git status
# Not currently on any branch.
nothing to commit (working directory clean)
Ah ah, there is no change. If you read in detail the previous error message, git
informed us of this and recommended to use git rebase --skip
. He told us "If there is nothing left to stage, chances are that something else already introduced the same changes; you might want to skip this patch." So we just skip the commit and the rebase succeed.
$ git rebase --skip
HEAD is now at 7313eb3 master
Word of caution: Please note that git rebase --skip
will completely drop the commit that git
tried to rebase. In our case, this should be okay since git
is complaining this is an empty commit. If you think you've lost changes once the rebase is complete, you can use git reflog
to get the commit id of your repository before the rebase, and use git reset --hard
to get your depot back in that state (this is another destructive operation).
Quoting from here: http://wholemeal.co.nz/node/9
Huh?!? No, I didn't forget to use git add, I did it ... like ... 2 seconds ago!
Turns out that because there is no change from the patch git suspects something has gone wrong. Git expects a patch to have been applied, but the file has remained unchanged.
The error message is not very intuitive, but it does contain the answer. We just need to tell rebase to skip this patch. It's also not necessary to fix the conflict markers in the file. You will end up with the file version from the branch you are rebasing on.
$ git rebase --skip
That error message is a result of your git commit -a -m "merged"
. If you just fix up the file, then run git add <file>
, and git rebase --continue
, it should work fine. git rebase --continue
is trying to do a commit, but finding that there are no pending changes to commit (because you committed them already).
Change app/views/common/version.txt to
v1.4-alpha-01
At this point in the rebase, remember that you are resolving merge conflicts to show the progression of the non-master branch.
So, in rebasing from
A---B---C topic
/
D---E---F---G master
to
A*--B*--C* topic
/
D---E---F---G master
the conflict you are resolving is in how to create A* on the topic branch.
So after doing git rebase --abort
, the commands should be
git checkout topic
git rebase master
< make edits to resolve conflicts >
git add .
git rebase --continue
The behavior you're seeing is not what I would expect from a typical rebase with just this conflict. Consider using a separate branch to do this rebase (especially if you've already pushed the commits remotely that you're fast-forwarding). Also, git mergetool
can be helpful for resolving conflicts and remembering to issue a git add
.
In this minimal example, the rebase works as expected. Can you provide an example that shows the behavior you're seeing?
#!/bin/bash
cd /tmp
mkdir rebasetest
cd rebasetest
git init
echo 'v1.0' > version.txt
git add version.txt
git commit -m 'initial commit'
git checkout -b v4
echo 'v1.4-alpha-01' > version.txt
git add version.txt
git commit -m 'created v4'
git checkout master
git merge v4
echo 'v1.4-alpha-01-rc1' > version.txt
git add version.txt
git commit -m 'upped version on master to v1.4-alpha-01-rc1'
git checkout v4
echo 'v1.4-alpha-02' > version.txt
git add version.txt
git commit -m 'starting work on alpha-02'
git rebase master
echo 'v1.4-alpha-02' > version.txt
git add version.txt
git rebase --continue
Here are some ideas:
- Before starting the rebase, make sure you aren't in the middle of a rebase or am. Do:
rm -rf .git/rebase-apply
- One bit you mentioned I didn't understand: "and then try to carry on: at first i try a commit:"... why commit? In the middle of a rebase I think you should only "git add" after you tidy up or "git rm" to toss changes or confirm a file deletion. Maybe that messed something up?
- try a merge instead of a rebase
- try some of Ethan Rowe's ideas
참고URL : https://stackoverflow.com/questions/4033009/git-rebase-conflicts-keep-blocking-progress
'programing tip' 카테고리의 다른 글
Visual Studio에서 직접 실행 창을 어떻게 사용합니까? (0) | 2020.07.20 |
---|---|
REST 웹 서비스를위한 Spring 4 vs Jersey (0) | 2020.07.20 |
Git 리포지토리에서 마스터에 대한 오래된 브랜치 업데이트 (0) | 2020.07.20 |
Connect.js methodOverride의 기능은 무엇입니까? (0) | 2020.07.20 |
두 개의 문자열 리터럴 연결 (0) | 2020.07.20 |