假设我有一个提交,我意识到我想从中提取一个小块,并将小块作为单独的订单提交。
我已经知道使用多个命令来执行此操作的多种方法,一个示例是:
$ `git reset @^`
$ `git add -p` # Stage all but the small chunks I want to extract
$ `git commit` # Commit original (without the small chunks)
$ `git commit -a` # Commit the remaining chunks as a new commit
问题是,我想这样做,而不必手动上台并重新命令第一个提交。显然,提交哈希将会改变,但我想避免键入命令进行上台并提交初始提交。
换句话说,我理想地寻找一个git命令,可以立即让我: - 从最后一个提交中互动选择块 - 从提交中删除这些块(保留原始提交消息) - 将这些块放在索引上,以便我准备
这种命令是否存在?
no。我认为最短的方法是从您的列表中删除一个命令:
git reset @^
git commit -p
git commit -a
但是,从您在评论中的评论中,我认为您可能会发现的另一件事是git reset -p @^
-它显示的笨蛋是相反的,这有时可能会有些混乱,但这使您可以选择性地从上一个提交中进行选择性地变化。,启用这种工作流程:
git reset -p @^
# potentially more wrangling
git commit --amend
git commit -a