Method to withdraw after submitting the code: Find the error immediately: use the "git reset --soft HEAD~1" command. Pushed to the remote warehouse: Use the "git push -f origin
" command to force push the overwriting commit. Merged commits: Use the "git revert " command to create a rollback commit and then push it to the remote repository.
Withdraw after git commits the code
Quickly withdraw
If Upon realizing an error immediately after committing, you can undo the commit using the following command:
<code>git reset --soft HEAD~1</code>
This command will retain the changes in the staging area, but discard the most recent commit.
Withdraw a commit that has been pushed to the remote repository
If a commit has been pushed to the remote repository, it cannot be retracted directly. However, it can be overridden by forcing a push:
-f
flag to force a push of a new commit : <code>git push -f origin <branch-name></code>
This action will overwrite old commits in the remote repository.
Withdraw merged commits
If the commit has been merged into other branches, it cannot be withdrawn directly. However, it is possible to create a rollback commit to undo the changes:
using the
git revert command: <code>git revert <commit-hash></code>
<code>git push origin <branch-name></code>
This operation will create a new commit that will undo the changes made by the merged commit.
The above is the detailed content of How to withdraw the code after submitting it to git. For more information, please follow other related articles on the PHP Chinese website!