git commit撤销 - 取消commit

Posted Rudon滨海渔村

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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$ 

以上是关于git commit撤销 - 取消commit的主要内容,如果未能解决你的问题,请参考以下文章

[Git] 撤销提交commit

git上怎么把commit的代码撤销

git stash执行后,我本地未add,未commit的文件全没了,怎么恢复,求大神,非常感谢

未commit 执行git stash后怎么恢复

git取消本地commit

git commit 之后,撤销commit操作