Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 如何撤消上次提交_Git - Fatal编程技术网

Git 如何撤消上次提交

Git 如何撤消上次提交,git,Git,我忘记了在提交之前添加文件,因此我在git add之前进行了git提交 我怎么回去 使用git log,我得到: commit 606da2c2e5fb34cf0d971dce2930c4c9d921a46f Author: Name <email@hotmail.com> Date: Thu Mar 2 12:11:15 2017 +0100 Archive detail page added commit 606da2c2e5fb34cf0d971dce2930c

我忘记了在提交之前添加文件,因此我在git add之前进行了git提交

我怎么回去

使用git log,我得到:

commit 606da2c2e5fb34cf0d971dce2930c4c9d921a46f
Author: Name <email@hotmail.com>
Date:   Thu Mar 2 12:11:15 2017 +0100

    Archive detail page added
commit 606da2c2e5fb34cf0d971dce2930c4c9d921a46f
作者:姓名
日期:2017年3月2日星期四12:11:15+0100
已添加存档详细信息页面

如何撤消上次提交?

免责声明:如果您已推送,而其他人可能已推送,请不要执行此操作。

如果您只想将文件添加到该提交中:

git add <files>
git commit --amend --no-edit
git添加
git提交--修改--不编辑

否则,您可以完全撤消并重做提交,如下所述:

免责声明:如果您已经推送了,而其他人可能已经拉送了,请不要这样做。

如果您只想将文件添加到该提交中:

git add <files>
git commit --amend --no-edit
git添加
git提交--修改--不编辑

否则,您可以完全撤消并重做提交,如下所述:

您可以通过以下方式撤消上次提交:

 git reset --soft HEAD~ 
如果您在提交消息中有输入错误,并且只想编辑该消息,您可以执行以下操作:

git commit --amend
git rebase-reword <commit-id>
如果您进行了提交,但其中一个文件有错误。您可以进行更改,然后简单地更新提交

git add <file_path>
git commit --amend
git添加
修改最后一次提交
如果在历史记录中您在提交消息时出错,您可以执行以下操作:

git commit --amend
git rebase-reword <commit-id>
git-rebase-reword

编辑历史记录时要非常小心。如果您已将此更改推送到源站,这可能会导致其他参与者出现问题。

您可以通过以下方式撤消上次提交:

 git reset --soft HEAD~ 
如果您在提交消息中有输入错误,并且只想编辑该消息,您可以执行以下操作:

git commit --amend
git rebase-reword <commit-id>
如果您进行了提交,但其中一个文件有错误。您可以进行更改,然后简单地更新提交

git add <file_path>
git commit --amend
git添加
修改最后一次提交
如果在历史记录中您在提交消息时出错,您可以执行以下操作:

git commit --amend
git rebase-reword <commit-id>
git-rebase-reword

编辑历史记录时要非常小心。如果您已将此更改推送到源站,这可能会导致其他贡献者出现问题。

@AvihooMamka它是重复的。我应该接受其中一个答案还是删除该问题?如果您认为此处的一个答案以某种方式提供了比原始线程上的答案更好的解决方案,您可以接受它。@Avihoomaka它是重复的。我应该接受其中一个答案还是删除这个问题?如果你认为这里的一个答案以某种方式提供了比原始线程上的答案更好的解决方案,你可以接受它。