Home >Development Tools >git >How to withdraw after git commits to local warehouse
There are four ways to undo Git local submissions: Undo the latest submission: git reset HEAD~1 Undo and discard the changes (hard reset): git reset --hard HEAD~1 Modify the staging area (mixed heavy reset) Setting): git reset HEAD~1 -- path/to/file Check the latest commit: git log -1
How to withdraw local Git commit
If you change your mind after committing code to your local Git repository, you can retract the commit by following these steps:
1. Check for the latest commit
Use the following command to check the latest commit:
<code>git log -1</code>
2. Undo the latest commit
Use the following command to undo the latest commit:
<code>git reset HEAD~1</code>
This command will Undo the latest commit but still keep its modifications.
3. Undo and discard modifications (hard reset)
If you want to undo the latest commit and discard its modifications, you can use the following command:
<code>git reset --hard HEAD~1</code>
This command will undo the latest commit and discard all unstaged modifications.
4. Modify the staging area (hybrid reset)
If you only want to undo part of the latest submitted modifications, you can use the following command:
<code>git reset HEAD~1 -- path/to/file1 path/to/file2</code>
This command will undo the modifications to the specified file in the latest commit, but keep other modifications.
Note:
The above is the detailed content of How to withdraw after git commits to local warehouse. For more information, please follow other related articles on the PHP Chinese website!