标签:任务 mic 推荐 ack class commit deletion protected let
在使用 Git 作为版本控制的时,处于多种原因想修改commit。
git commit --amend
git reset HEAD^1
前两种情况简单,这里着重介绍第三种
$ git status
commit 1a607dcdc4ab522ce94b395fff5968c5035362b4
Author: 陈子云 <ever-lose@foxmail.com>
Date: Tue Mar 21 16:05:34 2017 +0800
changelog补上
commit a7bd84613243535f5a2de1d1f35037531ea153e3
Author: 陈子云 <ever-lose@foxmail.com>
Date: Tue Mar 21 16:03:14 2017 +0800
标签合并出错,html结构被改乱了
commit 8a7c40cd96153f1eb51648f46389c9ef4395c8a9
Author: 陈子云 <ever-lose@foxmail.com>
Date: Tue Mar 7 19:37:11 2017 +0800
chore(package.json): update verison to 2.2.2
在“标签合并出错,html 结构被改乱了”之后发现 changelog 还没写呢,于是在提交了一发 “changelog补上”,希望能把这两个提交合并成一个。
# You can do a soft reset and amend the changes to the root commit.
$ git reset HEAD^1
Unstaged changes after reset:
M CHANGELOG.md
$ git add ./
$ git commit --amend
[photoGallery df482e8] 标签合并出错,html结构被改乱了
Date: Tue Mar 21 16:03:14 2017 +0800
2 files changed, 18 insertions(+), 17 deletions(-)
合并成功
$ git log
commit df482e862824c9ba8335f6ca25491231b44fc9e1
Author: 陈子云 <ever-lose@foxmail.com>
Date: Tue Mar 21 16:03:14 2017 +0800
标签合并出错,html结构被改乱了
commit 8a7c40cd96153f1eb51648f46389c9ef4395c8a9
Author: 陈子云 <ever-lose@foxmail.com>
Date: Tue Mar 7 19:37:11 2017 +0800
chore(package.json): update verison to 2.2.2
最后 push 时需要加 -f 参数强制推送,若你在 develop 等保护分支上,记得先去去掉 protected branch
标签:任务 mic 推荐 ack class commit deletion protected let
原文地址:https://www.cnblogs.com/everlose/p/12825969.html