Git 交互式变基没有可供选择的提交
我在 master 上,我做了 rebase -i
得到了这个:
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.
#
我想选择一些提交,而不是全部,因为其中一些不受欢迎。 另外,当您想将某些文件或更改始终保留在某个分支的“本地”时,您该如何工作?有没有像 .gitignore
这样的助手?
I'm on master and I did 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
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
与非交互式变基一样,您必须变基到特定的提交。
对于非交互式变基,如果您提供当前提交的直接祖先,那么您就不会更改任何内容;使用交互式变基,您可以在要变基的提交之后编辑提交,即使该提交是当前提交的直接祖先,但您必须指定要从中编辑的此提交。
我不知道你的具体情况,但你可能想要这样的东西:
或者
Like a non-interactive rebase, you have to rebase onto a particular commit.
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.
I don't know the details of your situation but you might want something like this:
or
没有提交范围的
rebase -i
将不会显示任何提交。要对最后(例如 7)次提交进行变基,请使用以下命令:尽管这会重写历史记录,但请小心。如果提交已经推送,请勿执行此操作。
对于你的第二个问题:有一个包含你的更改的分支(基本上是一个配置分支),并定期将其他分支合并到其中。这样,更改就不会转移到其他分支。
rebase -i
without a commit range will not display any commits. To rebase the last, say, 7 commits use the following: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 into it. This way, the changes will not move to other branches.
当您使用 git rebase -i 时,您通常必须指定要从哪个提交执行变基。因此,例如,如果您想删除当前分支的最后 10 次提交中的一些提交,您可以执行以下操作:
When you're using
git rebase -i
, you usually have to specify from 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:正如其他人提到的,您需要指定提交范围。
(假设你和要编辑的提交在同一个分支)--
要指定提交,你可以使用 HEAD~5 简写或使用 sha 校验和(可以通过 git log 获取) )
事实上,如果任何提交是您要在树中删除/编辑/重写的提交的先行/祖先,则该提交都可以。这将列出编辑器中自
以来的所有提交(在 git 配置中定义)。从列表中,要删除提交,只需删除该特定行,保存并退出(vi 习惯:))文件+编辑器,然后执行 git rebase --continue对于第二个答案,我同意与针织
As others have mentioned, you need to specify a commit range.
(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
)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 dogit rebase --continue
For the second answer, I agree with knittl