git rebase 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18653323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:01:28  来源:igfitidea点击:

git rebase is not working

gitgithub

提问by Ashish Negi

I made some commits in my local repo and have pushed them to the online repo too.

我在本地 repo 中做了一些提交,并且也将它们推送到了在线 repo。

Then i realized that there are to many commits and i want to squash them into little. Preferably from second last oneto first one. i.e. keeping current commit and squashing all other my commits.

然后我意识到有很多提交,我想把它们压缩成小块。最好从second last onefirst one。即保持当前提交并压缩我的所有其他提交。

when i do

当我做

 git rebase -i origin/branch_name

Window with nooppops up. I do not see any pick. What should i do ?

窗口的noop弹出了。我没有看到任何pick。我该怎么办 ?

回答by Melebius

When I get the noopmessage, it usually means the branch used in the argument of git rebase -iis ahead of checked out branch.

当我收到noop消息时,通常意味着参数中使用的分支在git rebase -i检出分支之前。

git log A..B
# prints the commits between A's head and B's head

git log B..A
# prints nothing

git status
# On branch A

git rebase -i B
# got 'noop' because there are no commits in the log above

In this case, it helps to swap the two affected branches.

在这种情况下,它有助于交换两个受影响的分支。

git checkout B
git rebase -i A

回答by njzk2

The argument for the rebase command is the range of commits you want to squash. In your case, probably something like :

rebase 命令的参数是您要压缩的提交范围。在您的情况下,可能类似于:

git rebase -i <sha-1 for first commit>..HEAD^

(HEAD^ being the parent commit to the head of your branch).

(HEAD^ 是对分支负责人的父级提交)。

Then, you replace the pickcommands in the interactive script by squash

然后,您将pick交互式脚本中的命令替换为squash