git 交互式变基 - 编辑与中断
git interactive rebase - edit vs break
我试过用谷歌搜索这个但没能找到满意的答案。
想知道在git rebase -i
的交互模式下edit
和break
有什么区别。
根据评论,edit
使用commit,但修改时停止,而break
在指定位置停止。但是那有什么区别:
# Scenario 1
pick a9ca198 commit #1
pick 15948d1 commit #2
edit 2dbe941 commit #3 // this will apply commit #3 and then stop.
pick 33c012d commit #4
# Scenario 2
pick a9ca198 commit #1
pick 15948d1 commit #2
pick 2dbe941 commit #3
break // this will stop after commit #3
pick 33c012d commit #4
我都试过了,对我来说,它们似乎完全相同。
To interrupt the rebase (just like an "edit
" command would do, but without cherry-picking any commit first), use the "break
" command.
在您的情况下,不同之处在于:
- with
edit
on commit 3, 你仍然可以修改commit 3的文件内容(应用commit 3之后),commit(仍然是commit 3,但是modified/amended),然后继续应用(樱桃采摘)在 git rebase --continue
. 上提交 4
- with
break
在提交 3 之后,提交 4 将不会被应用。并且提交 3 已经应用(如果您更改文件,添加并提交,这将创建一个新的提交,除非您执行 git commit --amend
)。
所以主要区别是:
edit
:应用提交 3,但允许您修改最终结果。然后恢复并应用提交 4.
break
: 不应用提交 4(仅在恢复变基时应用)
如果 break
单独在线,那么是的,它可以类似于提交 3 上的 edit
,前提是您执行 git commit --amend
(因为提交 3 已经是 cherry -在上一行中选择)
但是git rebase --continue
(在add
+commit --amend
之后)会停止,因为break
.
如DylanYoung puts it in :
It allows you to break immediately after an exec
or merge
, which was not possible before.
注意:break
是在 Git v1.5.3-rc0, June 2007, commit 1b1dce4 中通过交互式变基引入的。
但是命令 break
是最近的:Git v2.20.0-rc0, Oct. 2018, commit 71f8246
参见 commit 71f8246 (12 Oct 2018), and commit b8c0b21 (10 Oct 2018) by Johannes Schindelin (dscho
)。
(由 Junio C Hamano -- gitster
-- in commit 789b1f7 合并,2018 年 11 月 2 日)
"git rebase -i
" learned a new instruction ("insn"), 'break
', that the user can insert in the to-do list.
Upon hitting it, the command returns control back to the user.
rebase -i
: introduce the 'break
' command
The 'edit
' command can be used to cherry-pick a commit and then
immediately drop out of the interactive rebase, with exit code 0, to let
the user amend the commit, or test it, or look around.
Sometimes this functionality would come in handy without
cherry-picking a commit, e.g. to interrupt the interactive rebase even
before cherry-picking a commit, or immediately after an 'exec
' or a
'merge
'.
This commit introduces that functionality, as the spanking new 'break
'
command.
参见"Give me a break"... well, you gave me one:
Just wanted to express my gratitude for your idea to introduce the break
command in git rebase -i
's todo list. I use it all the time now.
Before that, I was using x bash
, and ended up doing git rebase --continue
in that shell in many cases, which didn't end up so well
when I terminated said shell (just an error message, though, nothing
actually broke as a consequence). This feature is a blessing.
或者:
'x bash
' will start another shell, that seems an odd thing to do.
I have been using 'x false
' to generate an error exit status to interrupt
the rebase and drop into the current shell.
Then 'git rebase --continue
' to resume.
b
is much shorter to type than x false
(and I also cannot
tyop it late at night as x flase
, although that would have the same
effect, I guess, of stopping the interactive rebase).
我使用 break
做的一件事 edit
不能做的是应用 fixup
然后做其他事情,比如更新代码审查。
例如如果我有
pick commit1 feature x
pick commit2 feature y
pick commit3 fixup for feature x
我可以
$ git rebase --interactive
pick commit1 feature x
fixup commit3 fixup for feature x
break
pick commit2 feature y
然后
$ command-to-update-cr
$ git rebase --continue
请注意,您可以使用 exec
来达到同样的目的,但我更喜欢从命令行中获得的控制权。
在您提供的示例中,您是正确的。在 pick
之后使用 break
与仅使用 edit
相同。这样使用 break
是没有意义的。 break
有用的地方是它跟在 squash
、fixup
、merge
或 exec
.
之后
这在the commit message that introduced the break
command中有解释:
rebase -i: introduce the 'break' command
The edit
command can be used to cherry-pick a commit and then
immediately drop out of the interactive rebase, with exit code 0, to let
the user amend the commit, or test it, or look around.
Sometimes this functionality would come in handy without
cherry-picking a commit, e.g. to interrupt the interactive rebase even
before cherry-picking a commit, or immediately after an exec
or a
merge
.
This commit introduces that functionality, as the spanking new break
command.
我试过用谷歌搜索这个但没能找到满意的答案。
想知道在git rebase -i
的交互模式下edit
和break
有什么区别。
根据评论,edit
使用commit,但修改时停止,而break
在指定位置停止。但是那有什么区别:
# Scenario 1
pick a9ca198 commit #1
pick 15948d1 commit #2
edit 2dbe941 commit #3 // this will apply commit #3 and then stop.
pick 33c012d commit #4
# Scenario 2
pick a9ca198 commit #1
pick 15948d1 commit #2
pick 2dbe941 commit #3
break // this will stop after commit #3
pick 33c012d commit #4
我都试过了,对我来说,它们似乎完全相同。
To interrupt the rebase (just like an "
edit
" command would do, but without cherry-picking any commit first), use the "break
" command.
在您的情况下,不同之处在于:
- with
edit
on commit 3, 你仍然可以修改commit 3的文件内容(应用commit 3之后),commit(仍然是commit 3,但是modified/amended),然后继续应用(樱桃采摘)在git rebase --continue
. 上提交 4
- with
break
在提交 3 之后,提交 4 将不会被应用。并且提交 3 已经应用(如果您更改文件,添加并提交,这将创建一个新的提交,除非您执行git commit --amend
)。
所以主要区别是:
edit
:应用提交 3,但允许您修改最终结果。然后恢复并应用提交 4.break
: 不应用提交 4(仅在恢复变基时应用)
如果 break
单独在线,那么是的,它可以类似于提交 3 上的 edit
,前提是您执行 git commit --amend
(因为提交 3 已经是 cherry -在上一行中选择)
但是git rebase --continue
(在add
+commit --amend
之后)会停止,因为break
.
如DylanYoung puts it in
It allows you to break immediately after an
exec
ormerge
, which was not possible before.
注意:break
是在 Git v1.5.3-rc0, June 2007, commit 1b1dce4 中通过交互式变基引入的。
但是命令 break
是最近的:Git v2.20.0-rc0, Oct. 2018, commit 71f8246
参见 commit 71f8246 (12 Oct 2018), and commit b8c0b21 (10 Oct 2018) by Johannes Schindelin (dscho
)。
(由 Junio C Hamano -- gitster
-- in commit 789b1f7 合并,2018 年 11 月 2 日)
"
git rebase -i
" learned a new instruction ("insn"), 'break
', that the user can insert in the to-do list.
Upon hitting it, the command returns control back to the user.
rebase -i
: introduce the 'break
' commandThe '
edit
' command can be used to cherry-pick a commit and then immediately drop out of the interactive rebase, with exit code 0, to let the user amend the commit, or test it, or look around.Sometimes this functionality would come in handy without cherry-picking a commit, e.g. to interrupt the interactive rebase even before cherry-picking a commit, or immediately after an '
exec
' or a 'merge
'.This commit introduces that functionality, as the spanking new '
break
' command.
参见"Give me a break"... well, you gave me one:
Just wanted to express my gratitude for your idea to introduce the
break
command ingit rebase -i
's todo list. I use it all the time now.Before that, I was using
x bash
, and ended up doinggit rebase --continue
in that shell in many cases, which didn't end up so well when I terminated said shell (just an error message, though, nothing actually broke as a consequence). This feature is a blessing.
或者:
'
x bash
' will start another shell, that seems an odd thing to do.I have been using '
x false
' to generate an error exit status to interrupt the rebase and drop into the current shell.
Then 'git rebase --continue
' to resume.
b
is much shorter to type thanx false
(and I also cannot tyop it late at night asx flase
, although that would have the same effect, I guess, of stopping the interactive rebase).
我使用 break
做的一件事 edit
不能做的是应用 fixup
然后做其他事情,比如更新代码审查。
例如如果我有
pick commit1 feature x
pick commit2 feature y
pick commit3 fixup for feature x
我可以
$ git rebase --interactive
pick commit1 feature x
fixup commit3 fixup for feature x
break
pick commit2 feature y
然后
$ command-to-update-cr
$ git rebase --continue
请注意,您可以使用 exec
来达到同样的目的,但我更喜欢从命令行中获得的控制权。
在您提供的示例中,您是正确的。在 pick
之后使用 break
与仅使用 edit
相同。这样使用 break
是没有意义的。 break
有用的地方是它跟在 squash
、fixup
、merge
或 exec
.
这在the commit message that introduced the break
command中有解释:
rebase -i: introduce the 'break' command
The
edit
command can be used to cherry-pick a commit and then immediately drop out of the interactive rebase, with exit code 0, to let the user amend the commit, or test it, or look around.Sometimes this functionality would come in handy without cherry-picking a commit, e.g. to interrupt the interactive rebase even before cherry-picking a commit, or immediately after an
exec
or amerge
.This commit introduces that functionality, as the spanking new
break
command.