githug rename_commit 修改已经commit但还没push的一条message
Posted hangj
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了githug rename_commit 修改已经commit但还没push的一条message相关的知识,希望对你有一定的参考价值。
githug 第 45 关, 一开始对 git rebase -i 这个东西有误解, 记录一下正确的用法
ddmobadeMac-mini:git_hug ddmoba$ githug reset 45
********************************************************************************
* Githug *
********************************************************************************
resetting level
Name: rename_commit
Level: 45
Difficulty: ***
Correct the typo in the message of your first (non-root) commit.
ddmobadeMac-mini:git_hug ddmoba$
查找有拼写错误的那一条 commit
ddmobadeMac-mini:git_hug ddmoba$ git log
commit d30bc005638c278714faaa73f0fdc16052561750 (HEAD -> master)
Author: hangj <[email protected]>
Date: Fri Jun 29 11:35:05 2018 +0800
Second commit
commit 4f1341ac9134225719e5d704e420160657e8c38e
Author: hangj <[email protected]>
Date: Fri Jun 29 11:35:05 2018 +0800
First coommit
commit a632e3dfa31a06bcec9395c0690d43a3f2f09706
Author: hangj <[email protected]>
Date: Fri Jun 29 11:35:05 2018 +0800
Initial commit
ddmobadeMac-mini:git_hug ddmoba$
First coommit // commit 写错了
git rebase -i parent_of_flawed_commit
ddmobadeMac-mini:git_hug ddmoba$ git rebase -i a632e3dfa31a06bcec9395c0690d43a3f2f09706
然后跳到
pick 4f1341a First coommit
pick d30bc00 Second commit
# Rebase a632e3d..d30bc00 onto a632e3d (2 commands)
#
# 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, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
~
~
~
~
~
~
~
~
~
~
~
~
"~/git_hug/.git/rebase-merge/git-rebase-todo" 21L, 693C
编辑它,
r 4f1341a First coommit
pick d30bc00 Second commit
# Rebase a632e3d..d30bc00 onto a632e3d (2 commands)
#
# 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, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
~
~
~
~
~
~
~
~
~
~
~
~
-- INSERT --
然后 :x 保存, 会跳到
First coommit
# Please enter the commit message for your changes. Lines starting
# with ‘#‘ will be ignored, and an empty message aborts the commit.
#
# Date: Fri Jun 29 11:35:05 2018 +0800
#
# interactive rebase in progress; onto a632e3d
# Last command done (1 command done):
# r 4f1341a First commit
# Next command to do (1 remaining command):
# pick d30bc00 Second commit
# You are currently editing a commit while rebasing branch ‘master‘ on ‘a632e3d‘.
#
# Changes to be committed:
# new file: file1
#
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"~/git_hug/.git/COMMIT_EDITMSG" 17L, 520C
编辑它, 把 coommit 改成 commit
First commit
# Please enter the commit message for your changes. Lines starting
# with ‘#‘ will be ignored, and an empty message aborts the commit.
#
# Date: Fri Jun 29 11:35:05 2018 +0800
#
# interactive rebase in progress; onto a632e3d
# Last command done (1 command done):
# r 4f1341a First commit
# Next command to do (1 remaining command):
# pick d30bc00 Second commit
# You are currently editing a commit while rebasing branch ‘master‘ on ‘a632e3d‘.
#
# Changes to be committed:
# new file: file1
#
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
-- INSERT --
然后 :x 保存, 跳到
ddmobadeMac-mini:git_hug ddmoba$ git rebase -i a632e3dfa31a06bcec9395c0690d43a3f2f09706
[detached HEAD ea3efe3] First commit
Date: Fri Jun 29 11:35:05 2018 +0800
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file1
Successfully rebased and updated refs/heads/master.
然后 git log 查看一下是否修改成功
ddmobadeMac-mini:git_hug ddmoba$ git log
commit 1f929783b1acb295aaf7b9dbe500629a1054484f (HEAD -> master)
Author: hangj <[email protected]>
Date: Fri Jun 29 11:35:05 2018 +0800
Second commit
commit ea3efe310a6a03a232171bf664401f62a5dc024e
Author: hangj <[email protected]>
Date: Fri Jun 29 11:35:05 2018 +0800
First commit
commit a632e3dfa31a06bcec9395c0690d43a3f2f09706
Author: hangj <[email protected]>
Date: Fri Jun 29 11:35:05 2018 +0800
Initial commit
ddmobadeMac-mini:git_hug ddmoba$
done !!
以上是关于githug rename_commit 修改已经commit但还没push的一条message的主要内容,如果未能解决你的问题,请参考以下文章