【发布时间】:2021-10-02 06:17:18
【问题描述】:
在问题How to git rebase -i edit and see past commits changes 中,作者给出了使用git reset 的解决方案。但是,该解决方案丢失了已编辑提交的提交消息。有什么方法可以编辑特定的提交(不是最新的提交)并在编辑时恢复所有更改?
例如,这是我执行的命令。
user$ ~/test_git(main○)» touch a
user$ ~/test_git(main⚡)» git add -A 1 ↵
user$ ~/test_git(main⚡)» git commit -m "a"
[main (root-commit) 50fc2a7] a
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a
user$ ~/test_git(main○)» touch b
user$ ~/test_git(main⚡)» git add -A
user$ ~/test_git(main⚡)» git commit -m "b"
[main ec313ba] b
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b
user$ ~/test_git(main○)» git rebase HEAD~1 -i
> edit ec313ba b
Stopped at ec313ba... b
You can amend the commit now, with
git commit --amend
Once you are satisfied with your changes, run
git rebase --continue
我实际上从git status得到什么
user$ ~/test_git(ec313ba○)» git status
interactive rebase in progress; onto 50fc2a7
Last command done (1 command done):
edit ec313ba b
No commands remaining.
You are currently editing a commit while rebasing branch 'main' on '50fc2a7'.
(use "git commit --amend" to amend the current commit)
(use "git rebase --continue" once you are satisfied with your changes)
nothing to commit, working tree clean
我想得到什么
user$ ~/test_git(50fc2a7⚡)» git status
interactive rebase in progress; onto 50fc2a7
Last command done (1 command done):
edit ec313ba b
No commands remaining.
You are currently editing a commit while rebasing branch 'main' on '50fc2a7'.
(use "git commit --amend" to amend the current commit)
(use "git rebase --continue" once you are satisfied with your changes)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: b
我希望将我编辑的提交更改为 Changes to be committed 并保留该消息。
【问题讨论】:
-
“恢复所有更改”是什么意思?
标签: git