在Git中将许多提交重新分配给一个提交。我究竟做错了什么? [英] Rebase many commits to one in Git. What am I doing wrong?

查看:544
本文介绍了在Git中将许多提交重新分配给一个提交。我究竟做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将许多提交合并为一个。我遵循之前的StackOverflow中描述的方法 answer 说:

 #回到我们想要形成初始提交的最后一个提交(分离HEAD)
git checkout< sha1_for_B>

#将分支指针重置为初始提交
#,但保持索引和工作树不变。
git reset --soft< sha1_for_A>

#使用'B'中的树修改初始树
git commit --amend

#暂时标记这个新的初始提交
#(或者您可以手动记住新的提交sha1)
git tag tmp

#返回原始分支(假设此示例为master)
git checkout master

#在B之后重放所有提交至新的初始提交
git rebase --onto tmp< sha1_for_B>

#删除临时标记
git tag -d tmp

我假设上面代码块中的B是最老的提交。



以下是我遇到的情况:

  $ cd rebase-test 
$ git branch
gui
* master
$ git log --pretty = oneline
7391d1b8e51b766190794ede49e3338307a64225合并分支'gui'
c69d44b0d3615d4f537ca42fe67ee58e2728a31a工作正在进行中。下一个端口转换()
e710a839c5aee0b07178da1f97999fa6dba445d6 audio_load()在callback.c中实现
...
$ git checkout c69d44b0d3615d4f537ca42fe67ee58e2728a31a
注意:移动到'c69d44b0d3615d4f537ca42fe67ee58e2728a31a'这不是本地分支
如果你想从这个结账中创建一个新的分支,你可以再次使用-b和checkout命令来完成
(现在或以后)。例如:
git checkout -b< new_branch_name>
HEAD现在在c69d44b ...正在进行中。下一个端口转换()
$ git reset --soft 7391d1b8e51b766190794ede49e3338307a64225
$ git commit --amend
[detached HEAD ad4e92a] new
$ git tag tmp
$ git checkout gui
上一个HEAD位置是ad4e92a ... new
转换到分支'gui'
$ git rebase --onto tmp c69d44b0d3615d4f537ca42fe67ee58e2728a31a
首先,回头重播您的作品顶部...
应用:删除构建文件
应用:删除更多构建文件
应用:修复infile_handler崩溃
/home/louise/rebase-test/.git/ rebase-apply / patch:90:缩进前的空格。
for(int j = 0; j< data-> audio_info_load-> channels; j ++){
/home/louise/rebase-test/.git/rebase-apply/patch:91 :缩进前的空格。
if(j == selected_channel){
/home/louise/rebase-test/.git/rebase-apply/patch:92:缩进前的空格。
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:缩进前的空格。
}
/home/louise/rebase-test/.git/rebase-apply/patch:94:缩进前的空格。
}
警告:5行添加空格错误。
应用:sf_readf_double()崩溃
应用:崩溃固定
应用:创建audio_load()
/home/louise/rebase-test/.git/rebase-apply/patch: 73:缩进前的空格。
for(int j = 0; j< data-> audio_info_load-> channels; j ++){
/home/louise/rebase-test/.git/rebase-apply/patch:74 :缩进前的空格。
if(j == selected_channel){
/home/louise/rebase-test/.git/rebase-apply/patch:75:缩进前的空格。
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:缩进前的空格。
}
/home/louise/rebase-test/.git/rebase-apply/patch:77:缩进前的空格。
}
警告:5行添加空格错误。
应用:清理
/home/louise/rebase-test/.git/rebase-apply/patch:58:尾随空格。

/home/louise/rebase-test/.git/rebase-apply/patch:60:尾随空格。

/home/louise/rebase-test/.git/rebase-apply/patch:67:尾随空格。

/home/louise/rebase-test/.git/rebase-apply/patch:72:尾随空格。

/home/louise/rebase-test/.git/rebase-apply/patch:80:尾随空格。

警告:禁止11个空白错误
警告:16行添加空白错误。
应用:transform_inv()实现
/home/louise/rebase-test/.git/rebase-apply/patch:115:尾随空格。
free(data-> mono_channel);
警告:1行添加空格错误。
应用:audio_save()崩溃
应用:崩溃固定
应用:后端最终在gui中实现。
$ git tag -d tmp
删除标记'tmp'

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



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

拥抱,
Louise



编辑:我已更新输出,因此它显示我继续时发生的情况。

解决方案

如果您想要做的是做到这一点:

  ABCDE 

转换为:

  A-BCD-E 

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

  $ git rebase -i< sha1_for_A> 

然后编辑:

 挑选B 
挑选C
挑选D
挑选E

阅读:

  pick B 
squash C
squash D
选择E

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



不过,如果您想创建

  ABCD-E 

(换句话说,如果您想要在合并提交中包含资源库的第一次提交),忘记这个答案,并看看已批准的答案您提到的问题。


I would like to combine many commits in to one. I have followed the method described at a previous StackOverflow answer which says:

# 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

I assume that B in the above code block is the oldest commit.

Here is what happens to me:

$ 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'

I get the same error, when I assume that A is the oldest.

Can someone see what's going wrong?

Hugs, Louise

Edit: I have updated the output, so it shows what happens when I continue.

解决方案

If what you want to do is make this:

A-B-C-D-E

into:

A-BCD-E

You can simply give this command:

$ git rebase -i <sha1_for_A>

And then edit this:

pick B
pick C
pick D
pick E

to read:

pick B
squash C
squash D
pick E

If there are no conflicts, you are done.

However, if you want to create

ABCD-E

(in other words if you want to include the first commit of the repository in the combined commit), forget this answer and have a look at the approved answer of the question you refer to.

这篇关于在Git中将许多提交重新分配给一个提交。我究竟做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆