这种Git重定基址的尝试有什么问题?

这种Git重定基址的尝试有什么问题?,git,rebase,git-rebase,Git,Rebase,Git Rebase,我正在努力学习如何“按书”使用Git。与多个开发人员一起处理一个项目,我们共享同一个远程“源”。我正在一个与本地git repo不同的工作区开发代码 让我们给我的分行打电话br_ysap。我对代码进行了更改,并试图将这些更改引入我的分支,并最终引入master分支。远程master自上次我同步内容以来已更新。所以,我想将我的分支重设为当前主节点,然后应用我的更新、提交和推送 以下是我正在做的事情和回应: > git clone ... > git status On branch

我正在努力学习如何“按书”使用Git。与多个开发人员一起处理一个项目,我们共享同一个远程“源”。我正在一个与本地git repo不同的工作区开发代码

让我们给我的分行打电话
br_ysap
。我对代码进行了更改,并试图将这些更改引入我的分支,并最终引入
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
接下来,我将阶段化文件:

> 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
问题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
问题3:什么给了???不,我没有忘记git add,谢谢

当我尝试提交并推送分支时,什么也没做:

> git push origin br_ysap:br_ysap
Everything up-to-date
问题4:此重定基期流程有什么问题?


更新1:在@torek的描述之后,暗示我错过了最后一个提交步骤,我尝试执行
重基--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".

看起来分支最终被分离了,但在第1季度没有连接到`

,发生的是您复制的
Main/Init.c

cp../dev tree/Main/Init.c Main/Init.c

(然后,
git add
ed)匹配您要重定基址的树中的版本

请记住,
git-rebase
的工作原理是:进入一个匿名分支,该分支从
--扩展到
commit。默认情况下,该分支指向您要重定的分支提示,在本例中为
master
--的提示,然后对要复制的提交集中的每个提交重复一次
git-cherry-pick
。(在本例中,要复制的提交是git log master..br_ysap列出的提交。)

您当前的提交(rebase的中间或真正开始)是对正在构建的
git rebase
匿名分支的提交。我会给这家分店起个名字,让它更容易看。事情是这样的(我假设在原始基础和再基础之间有一组非常短的提交,所以
master
部分可能太短了,但是这个想法应该足够清楚):

Git现在继续使用
Git cherry pick
ing commit
B
,这很好,没有冲突。如果您
Git显示原始
B
,并查看此时
rebase temp
中的内容,您就会明白为什么。在任何情况下,我们现在有:

          A - B - C - ... - S  <-- br_ysap
        /
... - o - o - o - T   <-- master
                   \
                    A' - B'   <-- rebase-temp
您没有执行“跳过”步骤,因此重新基础仍在进行中,并且您的分支标签
br_ysap
仍然指向原始提交
C
,而不是复制的提交
B'
。因此,
git push origin br_ysap
找不到要推的内容


1是否“一样好”取决于您在解决合并冲突时所做的工作有多好


2另一种可能性是,与旧的
br_ysap
master
连接的“合并基础”相比,它对一些其他文件进行了更改,这些更改与git能够检测到的更改相匹配。不过,我相信在本例中您会看到“退回到…3路合并”消息。

在第1季度,发生的情况是您复制的
Main/Init.c

cp../dev tree/Main/Init.c Main/Init.c

(然后,
git add
ed)匹配您要重定基址的树中的版本

请记住,
git-rebase
的工作原理是:进入一个匿名分支,该分支从
--扩展到
commit。默认情况下,该分支指向您要重定的分支提示,在本例中为
master
--的提示,然后对要复制的提交集中的每个提交重复一次
git-cherry-pick
。(在本例中,要复制的提交是git log master..br_ysap
列出的提交。)

您当前的提交(rebase的中间或真正开始)是对正在构建的
git rebase
匿名分支的提交。我会给这家分店起个名字,让它更容易看。事情是这样的(我假设在原始基础和再基础之间有一组非常短的提交,所以
master
部分可能太短了,但是这个想法应该足够清楚):

Git现在继续使用
Git cherry pick
ing commit
B
,这很好,没有冲突。如果您
Git显示原始
B
,并查看此时
rebase temp
中的内容,您就会明白为什么。在任何情况下,我们现在有:

          A - B - C - ... - S  <-- br_ysap
        /
... - o - o - o - T   <-- master
                   \
                    A' - B'   <-- rebase-temp
您没有执行“跳过”步骤,因此重新基础仍在进行中,并且您的分支标签
br_ysap
仍然指向原始提交
C
,而不是复制的提交
B'
。因此,
git push origin br_ysap
找不到要推的内容


1是否“一样好”取决于您在解决合并冲突时所做的工作有多好


2另一种可能性是,与旧的
br_ysap
master
连接的“合并基础”相比,它对一些其他文件进行了更改,这些更改与git能够检测到的更改相匹配。不过,我相信在这种情况下,您会看到“退回到……三方合并”消息。

谢谢您详细的回答。在我看来,人们需要对git及其术语有更深入的了解
> 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".
> 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
          A - B - C - ... - S  <-- br_ysap
        /
... - o - o - o - T   <-- master, rebase-temp
          A - B - C - ... - S  <-- br_ysap
        /
... - o - o - o - T   <-- master
                   \
                    A'   <-- rebase-temp
          A - B - C - ... - S  <-- br_ysap
        /
... - o - o - o - T   <-- master
                   \
                    A' - B'   <-- rebase-temp
          A - B - C - ... - S  [abandoned]
        /
... - o - o - o - T   <-- master
                   \
                    A' - B' - D' - ... - S'  <-- br_ysap