git commit撤销 - 取消commit

git add和git commit后,想撤销commit,怎么办?

git reset --soft HEAD^

搞定~ (以上命令要一字不差

其他:

ubuntu@vps008:/path/to/repo$ git commit -m "ProjectName small improve"
[master 3326c11c] ProjectName small improve
 Committer: ubuntu <ubuntu@localhost.localdomain>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 4 files changed, 6 insertions(+), 19 deletions(-)
 delete mode 100755 xxx.com/.htaccess
ubuntu@vps008:/path/to/repo$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	xxx.com/

nothing added to commit but untracked files present (use "git add" to track)
ubuntu@vps008:/path/to/repo$ git config --global --edit
ubuntu@vps008:/path/to/repo$ git commit --amend --reset-author
[master 8beb9366] ProjectName small improve
 4 files changed, 6 insertions(+), 19 deletions(-)
 delete mode 100755 xxx.com/.htaccess
ubuntu@vps008:/path/to/repo$ git push -u origin master
The authenticity of host 'gitee.com (212.64.64.193)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGkoFgbVr18bmjey0Wc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitee.com,212.64.64.193' (ECDSA) to the list of known hosts.
git@gitee.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
ubuntu@vps008:/path/to/repo$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	xxx.com/

nothing added to commit but untracked files present (use "git add" to track)
ubuntu@vps008:/path/to/repo$ git reset --soft HEAD^
ubuntu@vps008:/path/to/repo$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	modified:   d1/assets/css/my.css
	modified:   d1/index.php
	modified:   d2/test4git/index.php
	deleted:    xxx.com/.htaccess

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	xxx.com/

ubuntu@vps008:/path/to/repo$ 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Rudon滨海渔村

花的越多,赚得越多...

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值