Home >Development Tools >git >How to withdraw local code submitted by git
Can retract local Git commits: Determine the commit hash to be retracted. Undo changes in the staging area: git checkout --
. Undo committed changes: git reset --soft . Commit changes: git commit -m "undo commit".
How to retract a Git local commit
Git allows developers to commit code changes. However, there may be times when you need to retract commits made to your local repository. Here's how to do this:
Step 1: Identify the commits you want to retract
Use the git log
command to view the commit history. Find the commit hash you want to retract.
Step 2: Undo modifications in the staging area
If you want to undo modifications in the staging area, use the following command:
git checkout -- <File path>
For example:
git checkout -- File name.txt
Step 3: Undo the submitted changes
If you want to undo the submitted changes, please use the following command:
git reset --soft <Commit Hash Value >
For example:
git reset --soft abcd1234
This command will undo the committed modifications but keep them in in the staging area.
Step 4: Commit changes
Now, stage the changes and commit to update the local repository:
<code>git commit -m "撤回提交"``` **解决合并冲突** </code>
The above is the detailed content of How to withdraw local code submitted by git. For more information, please follow other related articles on the PHP Chinese website!