[Java] Java Core 82: Git Tutorial (5) Modify and Undo



insert image description here

In Git, different operations can be used to modify and undo commits. Here are a few commonly used methods:

Modify the last submission: If you need to modify the submission information of the last submission or miss some files, you can use the following command to modify:

git commit --amend

After executing this command, an editor will open and you can modify the submission information. If you just add missing files, you can add them to the temporary storage area before modifying, and then execute the above command.

Uncommit uncommitted changes: If you have made some changes in the workspace but have not committed them, you can use the following command to undo these changes:

git checkout -- <文件名>

Alternatively, if you want to undo all uncommitted changes, you can use the following command:

git checkout -- .

Note that this will discard all uncommitted changes in the workspace, use with caution.

Undoing committed changes: If you have committed some changes, but want to roll back to the previous version, you can use the git revert command to create a new commit to undo the previous changes. Execute the following command:

git revert <commit号>

<commit number> is the identifier of the specific commit to be rolled back. After executing this command, Git will create a new commit to undo the changes in the specified commit, keeping the previous commit record.

Note: When using g it revertto create a new submission to undo the changes, you need to provide comments for undoing the submission in the editor

Additional note: If you need to modify multiple commits of history or perform more advanced version control operations, you can consider using commands such as Interactive Rebase (Interactive Rebase), but these commands need to be used with caution because they will change the order of commits and identifiers, which may affect teamwork.


08. GIT local operation - modification and undo

Target
掌握 git checkout、git reset head作用

content

insert image description here

When we want to submit the content of our workspace to the cache [add], we suddenly find that there is a problem, what should we do if we want to cancel it?

When we have submitted the content to the cache area and found a bug, how should we deal with it?

We can use the undo command provided by GIT to complete the above operations

  • Workspace Undo Modifications

    Edit readme.txt to add "I am the fourth line"

insert image description here

Before you submit the cache, you suddenly find that this modification is problematic, and you plan to restore it to the original state. what to do?

Use the git status command to view the current status

insert image description here

命令:git checkout  文件名称 
    撤销工作区修改

insert image description here

After we revoked, we checked the contents of the file and found that the content of the workspace had been revoked, and checked the status, and found that the status was clean

  • Temporary storage area undo modification

    Use the vim command to edit readme.txt to add "I am the fifth line"

insert image description here

Use git add to submit files to the temporary storage area

insert image description here

undo to workspace

命令:git reset HEAD readme.txt 撤销到工作区

insert image description here

insert image description here

Workspace undo git checkout readme.txt

insert image description here

We are looking at the file and found that it has been restored to its original state

summary
  • How to Undo Modifications in the Workspace

    git checkout filename

  • How to revoke cache contents

    git reset HEAD filename


09. GIT local operation - summary

insert image description here

  • Initialize the workspace git init
  • View status git status
  • submit
    • Submit the temporary storage area git add file in the work area
    • Submit the local library in the staging area git commit -m 'commit information'
  • difference comparison
    • Workspace cache compare git diff filenames
    • Workspace local library comparison git diff head file name
    • Compare the cache area with the local library git diff --cached file name
  • version rollback
    • View log git log
    • Go back to the previous version git reset --hard head^
    • View all operation logs git reflog
    • Roll back to the specified version git reset --hard version number
  • modify undo
    • workspace undo git checkout filename
    • Undo the cache area (from the cache area to the work area) git reset head file name




insert image description here

Guess you like

Origin blog.csdn.net/m0_60915009/article/details/131457346