Git 交互式变基无需提交选择

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6485508/
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-10 11:15:47  来源:igfitidea点击:

Git interactive rebase no commits to pick

gitrebase

提问by Lukasz

I'm on master and I did rebase -i <my_branch>

我是大师,我做到了 rebase -i <my_branch>

Got this:

明白啦:

noop

# Rebase c947bec..7e259d3 onto c947bec
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x <cmd>, exec <cmd> = Run a shell command <cmd>, and stop if it fails
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

I would like to pick some commits not all as some of them are not welcome. Also how do you work when you want to keep some files or changes always 'local' to some branch? Is there some helper like .gitignore?

我想选择一些提交而不是全部,因为其中一些是不受欢迎的。另外,当您希望将某些文件或更改始终“本地”保存到某个分支时,您是如何工作的?有这样的帮手.gitignore吗?

采纳答案by CB Bailey

Like a non-interactive rebase, you have to rebase onto a particular commit.

像非交互式 rebase 一样,您必须 rebase 到特定的提交。

With a non-interactive rebase, if you supply a direct ancestor of the current commit then you aren't changing anything; with an interactive rebase you can edit commits after the commit that you are rebasing onto, even if the commit is a direct ancestor of your current commit but you do have to specify this commit that you want to edit onwards from.

使用非交互式 rebase,如果您提供当前提交的直接祖先,那么您不会更改任何内容;使用交互式变基,您可以在要变基的提交之后编辑提交,即使该提交是当前提交的直接祖先,但您必须指定要从其开始编辑的此提交。

I don't know the details of your situation but you might want something like this:

我不知道你的情况的细节,但你可能想要这样的东西:

# Opportunity to edit or prune commits between origin/master and current branch
git rebase -i origin/master

or

或者

# Edit some of the last ten commits
git rebase -i HEAD~10 # Note that ~10 uses a tilde("~") not a dash("-"_) !

回答by knittl

rebase -iwithout a commit range will not display any commits. to rebase the last, say, 7 commits use the following:

rebase -i没有提交范围将不会显示任何提交。要重新设置最后一次,例如 7 次提交,请使用以下内容:

git rebase -i HEAD~7

be careful though, that this will rewrite history. don't do it, if the commits are already pushed

不过要小心,这将改写历史。不要这样做,如果提交已经被推送



for your second question: have a branch with your changes (basically a configuration branch) and regularly merge the other branches intoit. this way the changes will not move to other branches

对于您的第二个问题:有一个包含您的更改的分支(基本上是一个配置分支)并定期将其他分支合并其中。这样更改就不会移动到其他分支

回答by svick

When you're using git rebase -i, you usually have to specify, since which commit do you want to perform the rebase. So, if, for example, you want to remove some of the commits among the last 10 to the current branch, you would do:

当您使用 时git rebase -i,您通常必须指定,因为您要执行变基的哪个提交。因此,例如,如果您想删除当前分支的最后 10 个提交中的一些提交,您可以这样做:

git rebase -i HEAD~10

回答by 0xc0de

As others have mentioned, you need to specify a commit range.

正如其他人所提到的,您需要指定一个提交范围。

git rebase -i <latest-commit-to-be-retained>

(Assuming that you are on the same branch as the commit to be edited)--

(假设您与要编辑的提交在同一分支上)--

To specify the commits, you can use the HEAD~5 shorthands or use sha checksum (which you can get by git log)

要指定提交,您可以使用 HEAD~5 速记或使用 sha checksum(您可以通过 获得git log

In fact any commit will do if it is prior/ancestor to the commits which you want to delete/edit/reword in the tree. This will list all the commits since the <latest-commit-to-be-retained>in the editor(defined in your git config). From the list, to delete a commit, just delete that particular line, save and exit (vi habbits :) )the file+editor, and do git rebase --continue

事实上,任何提交都可以,如果它是您要在树中删除/编辑/改写的提交的先前/祖先。这将列出自<latest-commit-to-be-retained>编辑器中的所有提交(在您的 git 配置中定义)。从列表中删除提交,只需删除该特定行,保存并退出(vi habbits :))文件+编辑器,然后执行git rebase --continue

For the second answer, I agree with knittl

对于第二个答案,我同意 knittl

have a branch with your changes (basically a configuration branch) and regularly merge the other branches into it. this way the changes will not move to other branches

有一个包含您的更改的分支(基本上是一个配置分支),并定期将其他分支合并到其中。这样更改就不会移动到其他分支