这个问题是后续问题这个问题 https://stackoverflow.com/questions/44513186/how-do-i-edit-a-commit-with-interactive-rebase-as-uncommited。它试图找到一种更简单的方法来在交互式变基期间编辑提交。
这是一个可以看到问题的完整示例:
mkdir git_example
cd git_example
git init
echo first > first
git add first
git commit -m "initial"
git tag initial
echo "How do I see this change while editing in interacive rebase" > second
git add second
git commit -m "second"
echo third > third
git add third
git commit -m "third"
git rebase -i initial
e 66127f1 second
pick 70c0b50 third
git reset HEAD~
git add .
git commit
# NOT commit --amend
# The commit message will be empty, that's ok
git rebase --continue
问题在于git reset HEAD~
以及它改变了 HEAD 的事实。这会破坏此提交中的提交消息,并给我们留下# The commit message will be empty, that's ok
.
有没有办法重置索引和工作树但保持 HEAD 完整?
的帮助git reset -h
列出所有组合而不是那个组合。
Using git-restore
有没有办法重置索引和工作树但保持 HEAD 完整?
这正是新的git-restore https://github.com/git/git/blob/master/Documentation/git-restore.txt命令用于:
使用恢复源中的某些内容恢复工作树中的指定路径。
默认情况下,git-restore https://github.com/git/git/blob/master/Documentation/git-restore.txt只会修改工作树,但你也可以告诉它更新索引:
该命令还可以用于恢复索引中的内容--staged
,或者使用以下命令恢复工作树和索引--staged --worktree
.
您可能会注意到此行为与git-reset
;两者之间的主要区别在于git-restore
不会碰HEAD
参考,这正是你想要的。
命令将是:
git restore --staged --worktree --source HEAD~
请记住git restore
仍在积极开展工作(文档将其列为实验性的),但这绝对是前进的方向。
Using git-show
or git-diff
还有另一种方法。如果您想在交互式变基期间查看与当前提交关联的补丁,则不必将索引重置为HEAD~
去做吧;相反,你可以简单地使用git-show https://git-scm.com/docs/git-show or git-diff https://git-scm.com/docs/git-diff.
那么您的工作流程将是:
git rebase -i initial
e 66127f1 second
pick 70c0b50 third
git show
# or
git diff HEAD~..HEAD
# Look at the patch generated by 66127f1
# Modify the files in your working directory as needed
git add .
git commit --amend
git rebase --continue
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)