Git actions-Modify and delete

Source: Internet
Author: User

Manage changes

First modification, git add second modification,git commit

If the first modification git add , the second modification has not come and ' git add ', at this time if git commit the second modification is not in the repository, git management is modified, when you use the git add command, the first modification in the workspace is put into staging area, ready to commit, but, The second modification in the workspace has not been put into staging area, so git commit is only responsible for submitting the staging area changes, i.e. the first modification is submitted, and the second modification is not committed.

First modification, git add Second Amendment, git addgit commit

So two changes are committed to the repository.

Undo Changes

Scenario 1: If you make some changes in the file, you haven't submitted it yet git add , but you can't undo it manually.
Method: You can git checkout -- file discard changes to the workspace at this time:

Another situation is that README.txt has been added to staging area and modified, and now the undo changes go back to the state that was added to the staging area.
All in all, git checkout -- file let this file go back to the state of the last git commit or git Add.

Scenario 2: If the changes in the file have been git add staging area, but have not yet been submitted, this time you want to undo staging area's changes
Method: You can use git reset HEAD file the command can be staging area to undo the changes (Unstage), re-put back to the workspace, note: The git reset command can be rolled back to the version, you can also staging area changes back to the workspace. When we use head, we represent the latest version.


At this point, the staging area is clean, the workspace has been modified, and then git checkout -- file the modification of the discard workspace is

deleting files

Scenario 1: A new file Test.txt has been created in the workspace and has been submitted to the repository, at which point the file will be deleted
Method: In the workspace can be deleted directly, the problem is how to delete test.txt in the repository, it can be deleted git rm , and then git commit , so that the file is deleted from the repository

Scenario 2: Test.txt was mistakenly deleted in the workspace, but the repository also has
Method: $ git checkout -- test.txt You can restore deleted files to the latest version

git checkoutInstead, replace the workspace version with the version in the repository, which can be "one-click Restore", regardless of whether the workspace is modified or deleted.

Git actions-Modify and delete

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.