2009-11-13 87 views
6

我想结合许多提交到一个。我按照在先前的StackOverflow answer描述的方法,其表示:在Git中重建许多提交到一个提交。我究竟做错了什么?

# Go back to the last commit that we want to form the initial commit (detach HEAD) 
git checkout <sha1_for_B> 

# reset the branch pointer to the initial commit, 
# but leaving the index and working tree intact. 
git reset --soft <sha1_for_A> 

# amend the initial tree using the tree from 'B' 
git commit --amend 

# temporarily tag this new initial commit 
# (or you could remember the new commit sha1 manually) 
git tag tmp 

# go back to the original branch (assume master for this example) 
git checkout master 

# Replay all the commits after B onto the new initial commit 
git rebase --onto tmp <sha1_for_B> 

# remove the temporary tag 
git tag -d tmp 

我假定乙在上面的代码块是最古老的提交。

以下是发生在我身上:

$ cd rebase-test 
$ git branch 
    gui 
* master 
$ git log --pretty=oneline 
7391d1b8e51b766190794ede49e3338307a64225 Merge branch 'gui' 
c69d44b0d3615d4f537ca42fe67ee58e2728a31a Work in progress. Next port transform() 
e710a839c5aee0b07178da1f97999fa6dba445d6 audio_load() implemeted in callback.c 
... 
$ git checkout c69d44b0d3615d4f537ca42fe67ee58e2728a31a 
Note: moving to 'c69d44b0d3615d4f537ca42fe67ee58e2728a31a' which isn't a local branch 
If you want to create a new branch from this checkout, you may do so 
(now or later) by using -b with the checkout command again. Example: 
    git checkout -b <new_branch_name> 
HEAD is now at c69d44b... Work in progress. Next port transform() 
$ git reset --soft 7391d1b8e51b766190794ede49e3338307a64225 
$ git commit --amend 
[detached HEAD ad4e92a] new 
$ git tag tmp 
$ git checkout gui 
Previous HEAD position was ad4e92a... new 
Switched to branch 'gui' 
$ git rebase --onto tmp c69d44b0d3615d4f537ca42fe67ee58e2728a31a 
First, rewinding head to replay your work on top of it... 
Applying: Removed build files 
Applying: Removed more build files 
Applying: Fixed infile_handler crash 
/home/louise/rebase-test/.git/rebase-apply/patch:90: space before tab in indent. 
     for(int j = 0; j < data->audio_info_load->channels; j++) { 
/home/louise/rebase-test/.git/rebase-apply/patch:91: space before tab in indent. 
      if(j == selected_channel) { 
/home/louise/rebase-test/.git/rebase-apply/patch:92: space before tab in indent. 
      data->mono_channel[while_counter * const_frames_read + i] = bufferIn[i * data->audio_info_load->channels + selected_channel]; 
/home/louise/rebase-test/.git/rebase-apply/patch:93: space before tab in indent. 
      } 
/home/louise/rebase-test/.git/rebase-apply/patch:94: space before tab in indent. 
     } 
warning: 5 lines add whitespace errors. 
Applying: sf_readf_double() crashes 
Applying: Crash fixed 
Applying: Created audio_load() 
/home/louise/rebase-test/.git/rebase-apply/patch:73: space before tab in indent. 
     for(int j = 0; j < data->audio_info_load->channels; j++) { 
/home/louise/rebase-test/.git/rebase-apply/patch:74: space before tab in indent. 
      if(j == selected_channel) { 
/home/louise/rebase-test/.git/rebase-apply/patch:75: space before tab in indent. 
      data->mono_channel[while_counter * const_frames_read + i] = bufferIn[i * data->audio_info_load->channels + selected_channel]; 
/home/louise/rebase-test/.git/rebase-apply/patch:76: space before tab in indent. 
      } 
/home/louise/rebase-test/.git/rebase-apply/patch:77: space before tab in indent. 
     } 
warning: 5 lines add whitespace errors. 
Applying: Clean up 
/home/louise/rebase-test/.git/rebase-apply/patch:58: trailing whitespace. 

/home/louise/rebase-test/.git/rebase-apply/patch:60: trailing whitespace. 

/home/louise/rebase-test/.git/rebase-apply/patch:67: trailing whitespace. 

/home/louise/rebase-test/.git/rebase-apply/patch:72: trailing whitespace. 

/home/louise/rebase-test/.git/rebase-apply/patch:80: trailing whitespace. 

warning: squelched 11 whitespace errors 
warning: 16 lines add whitespace errors. 
Applying: transform_inv() implemented 
/home/louise/rebase-test/.git/rebase-apply/patch:115: trailing whitespace. 
    free(data->mono_channel); 
warning: 1 line adds whitespace errors. 
Applying: audio_save() crash 
Applying: Crash fixed 
Applying: Backend finally implemented in gui. 
$ git tag -d tmp 
Deleted tag 'tmp' 

我得到同样的错误,当我假定A是最老的。

有人可以看到发生了什么问题吗?

拥抱, 路易丝

编辑:我已经更新了输出,所以它显示了当我继续会发生什么。

+1

错误?我没有看到任何错误... – 2009-11-13 15:51:21

+0

在上次输出git说“哪些不是本地分支”。我假设“本地”的意思是“在硬盘上”。 “gui”分支在我的硬盘上,而不是在互联网上。或者输出意味着什么? – Louise 2009-11-13 16:20:16

+0

您似乎已经在步骤1中停止,该步骤已成功完成(HEAD现在位于ddf5f7a ...),因此请继续完成配方的其余部分。 – 2009-11-13 18:13:12

回答

12

如果你想要做的是让这样的:

A-B-C-D-E 

到:

A-BCD-E 

你可以简单地给这个命令:

$ git rebase -i <sha1_for_A> 

,然后编辑这个:

pick B 
pick C 
pick D 
pick E 

阅读:

pick B 
squash C 
squash D 
pick E 

如果没有冲突,你就完成了。

然而,如果你想创建

ABCD-E 

(换句话说,如果你想包括先在联合提交的存储库提交),忘了这个答案,有一个看看您提到的问题的approved answer