Git operation-Modify and delete, git operation Modification

Source: Internet
Author: User

Git operation-Modify and delete, git operation Modification
Manage changes

First modification->git add-> Second modification->git commit

If you modifygit add, The second modification has not yet come and 'git add', ifgit commitThe second modification is not in the version library, and Git manages the modification. After you use the git add command, The first modification in the workspace is placed in the temporary storage area and ready to be submitted. However, the second modification in the workspace is not in the temporary workspace. Therefore, git commit is only responsible for submitting the modification to the temporary workspace, that is, the first modification is submitted, the second modification will not be submitted.

First modification->git add-> Second modification->git add->git commit

In this way, both modifications are submitted to the version library ..

Undo Modification

Scenario 1: If you make some changes in the file, you have not submittedgit addBut cannot be manually revoked.
Method: you cangit checkout -- fileDiscard workspace modification:

Another situation is that README.txt has been added to the temporary storage area and modified. Now, undo the modification and return to the state after it is added to the temporary storage area.
In short,git checkout -- fileIs to bring this file back to the status of the last git commit or git add.

Scenario 2: If the file has been modifiedgit addThe temporary storage area has been saved, but it has not been submitted. In this case, you need to cancel the modification of the temporary storage area.
Method: use commands.git reset HEAD fileYou can undo the modification of the temporary storage area (unstage) and put it back into the workspace. Note:git resetThe command can be used to roll back the version or to the workspace. When we use HEAD, it indicates the latest version.


In this case, the temporary storage area is clean, the workspace is modified, and then reused.git checkout -- fileDiscard workspace changes

Delete an object

Scenario 1: Create a new file test.txt in the work area and submit it to the version library. delete the file.
Method: You can delete test.txt directly in the work area.git rmAnd thengit commitIn this way, the file will be deleted from the version library.

Scenario 2: test.txt is deleted by mistake in the work area, but the version Library also has
Method:$ git checkout -- test.txtYou can restore accidentally deleted files to the latest version.

git checkoutIn fact, it is to replace the workspace version with the version in the version library. Whether the workspace is modified or deleted, you can "Restore it with one click ".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.