【发布时间】:2016-01-22 10:23:18
【问题描述】:
我正在努力学习如何“按部就班”地使用 Git。与多个开发人员一起处理一个项目,我们共享相同的“原点”遥控器。我正在与本地 git 存储库不同的工作区域中开发我的代码。
让我们打电话给我的分支br_ysap。我对我的代码进行了更改,并试图将它们引入我的分支,并最终引入master 分支。远程 master 自从我上次同步内容以来已更新。所以,我想将我的分支重新定位到当前的 master,然后应用我的更新、提交和推送。
这是我正在做的事情和回应:
> git clone ...
> git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
> git checkout br_ysap
Branch br_ysap set up to track remote branch br_ysap from origin.
Switched to a new branch 'br_ysap'
> git rebase master
First, rewinding head to replay your work on top of it...
Applying: SOME-COMMIT-COMMENT
Using index info to reconstruct a base tree...
M Main/Init.c
M Main/Main.c
A Service/Service_1.c
A Service/Service_2.c
M build_options.mk
Falling back to patching base and 3-way merge...
Auto-merging build_options.mk
Auto-merging Service/Service_3.c
CONFLICT (content): Merge conflict in Service/Service_3.c
Auto-merging Main/Main.c
CONFLICT (content): Merge conflict in Main/Main.c
Auto-merging Main/Init.c
CONFLICT (content): Merge conflict in Main/Init.c
Failed to merge in the changes.
Patch failed at 0001 SOME-COMMIT-COMMENT
The copy of the patch that failed is found in:
c:/local_repo/.git/rebase-apply/patch
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
在过去的某个时候,Service_2.c 被重命名为 Service_3.c。
现在,我在Main.c、Init.c 和Service_3.c 上收到“冲突”消息。接下来,我正在解决冲突。检查当前状态:
> git status
rebase in progress; onto fcd827a
You are currently rebasing branch 'br_ysap' on 'fcd827a'.
(fix conflicts and then run "git rebase --continue")
(use "git rebase --skip" to skip this patch)
(use "git rebase --abort" to check out the original branch)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: build_options.mk
Unmerged paths:
(use "git reset HEAD <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: Main/Init.c
both modified: Main/Main.c
both modified: Service/Service_3.c
所以,我现在将这 3 个文件从我的工作空间复制到 git 目录中(而不是使用合并工具并在代码中引入新的更新)。
> cp ../dev-tree/Main/Init.c Main/Init.c
> cp ../dev-tree/Main/Main.c Main/Main.c
> cp ../dev-tree/Service/Service_3.c Service/Service_3.c
按照this tutorial,然后我暂存文件:
> git add Main/Init.c Main/Main.c Service/Service_3.c
> git status
rebase in progress; onto fcd827a
You are currently rebasing branch 'br_ysap' on 'fcd827a'.
(all conflicts fixed: run "git rebase --continue")
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: Main/Init.c
modified: Service/Service_3.c
modified: build_options.mk
问题 1:Main/Main.c 发生了什么事?为什么没了?
接下来,按照说明,我继续变基:
> git rebase --continue
Applying: SOME-COMMIT-COMMENT
Applying: SOME-COMMIT-COMMENT - review update
Using index info to reconstruct a base tree...
M Main/Init.c
Falling back to patching base and 3-way merge...
Auto-merging Main/Init.c
CONFLICT (content): Merge conflict in Main/Init.c
Failed to merge in the changes.
Patch failed at 0002 SOME-COMMIT-COMMENT - review update
The copy of the patch that failed is found in:
c:/local_repo/.git/rebase-apply/patch
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
问题 2:为什么Main/Init.c 仍然存在冲突?我用我的新版本覆盖了文件?
检查状态、复制文件、添加和检查状态:
> git status
rebase in progress; onto fcd827a
You are currently rebasing branch 'br_ysap' on 'fcd827a'.
(fix conflicts and then run "git rebase --continue")
(use "git rebase --skip" to skip this patch)
(use "git rebase --abort" to check out the original branch)
Unmerged paths:
(use "git reset HEAD <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: Main/Init.c
no changes added to commit (use "git add" and/or "git commit -a")
> cp ../dev-tree/Main/Init.c Main/Init.c
> git add Main/Init.c
> git status
rebase in progress; onto fcd827a
You are currently rebasing branch 'br_ysap' on 'fcd827a'.
(all conflicts fixed: run "git rebase --continue")
nothing to commit, working directory clean
据说已经准备好完成变基了,不是吗?嗯:
> git rebase --continue
Applying: SOME-COMMIT-COMMENT - review update
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 prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
> git status
rebase in progress; onto fcd827a
You are currently rebasing branch 'br_ysap' on 'fcd827a'.
(all conflicts fixed: run "git rebase --continue")
nothing to commit, working directory clean
问题 3:什么给出了???不,我没有忘记git add,谢谢。
当我尝试提交和推送分支时,什么也没做:
> git push origin br_ysap:br_ysap
Everything up-to-date
问题 4:这个变基过程有什么问题?
更新 1: 按照@torek 的描述,暗示我错过了最后的提交步骤,我尝试执行rebase --skip。不幸的是,结果出乎意料且令人震惊:
> git rebase --skip
Applying: ANOTHER_COMMENT
Using index info to reconstruct a base tree...
A Application/App_3.c
M CSP/Driver_1.h
M CSP/Driver_1.c
A CSP/Driver_2.h
M CSP/Chip.h
M Common/Con_1.c
M Diags/Con_2.c
M Diags/Makefile
M Main/Init.c
M Main/Main.c
M Main/Makefile
M OS/Makefile
A Service/Service_4.h
A Service/Service_5.h
A Service/Service_2.c
<stdin>:592: trailing whitespace.
// $Id$
<stdin>:122074: trailing whitespace.
#define SOME_MOACRO_1
<stdin>:123643: trailing whitespace.
#define SOME_MOACRO_2
<stdin>:128989: trailing whitespace.
#define SOME_MOACRO_3
<stdin>:134620: trailing whitespace.
#define SOME_MOACRO_4
warning: squelched 9 whitespace errors
warning: 14 lines add whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging Service/Service_3.c
CONFLICT (content): Merge conflict in Service/Service_3.c
Auto-merging OS/Makefile
CONFLICT (content): Merge conflict in OS/Makefile
Auto-merging Main/Makefile
CONFLICT (content): Merge conflict in Main/Makefile
Auto-merging Main/Main.c
CONFLICT (content): Merge conflict in Main/Main.c
Auto-merging Main/Init.c
CONFLICT (content): Merge conflict in Main/Init.c
Auto-merging Diags/Makefile
CONFLICT (content): Merge conflict in Diags/Makefile
Auto-merging Diags/Con_2.c
CONFLICT (content): Merge conflict in Diags/Con_2.c
Auto-merging Common/Con_1.c
CONFLICT (content): Merge conflict in Common/Con_1.c
CONFLICT (modify/delete): Application/App_3.c deleted in HEAD and modified in ANOTHER_COMMENT Version ANOTHER_COMMENT of Application/App_3.c left in tree.
Failed to merge in the changes.
Patch failed at 0003 ANOTHER_COMMENT
The copy of the patch that failed is found in:
c:/local_repo/.git/rebase-apply/patch
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
更新 2: 在执行 --skip 之前,我复制了目录,以便可以从更新 1 之前的那一点开始进行试验。因此,更改为该副本,我尝试使用 commit --allow-empty 而不是--skip。我总是发现自己陷入了死胡同:
> git commit --allow-empty -m "YET-MORE-COMMENT"
[detached HEAD 4dd9e38] YET-MORE-COMMENT
> git status
rebase in progress; onto fcd827a
You are currently rebasing branch 'br_ysap' on 'fcd827a'.
(all conflicts fixed: run "git rebase --continue")
nothing to commit, working directory clean
看起来分支终于被分离了,但没有附加到`
【问题讨论】:
标签: git rebase git-rebase