Ios-git Undo operation (Distributed version control system)

Source: Internet
Author: User

1. Overwrite Submission
    • Sometimes when we are done, we find out that several files have not been added, or the submissions are wrong. At this point, you can run --amend the commit command with the option to attempt a resubmit.

      $ git commit --amend或# git commit --amend -m [提交内容说明]$ git commit --amend -m "Amend commit dsc"
      • This command will submit the file in the staging area. If you have not made any changes since the last commit (for example, the command was executed immediately after the last commit), the snapshot remains the same, and the only thing you have modified is the submission information.

      • Once the text editor is started, you can see the previous submission information. Saving after editing overwrites the original commit information.

    • For example, after you commit, you find that you forgot to temporarily save some of the changes you need, and you can do just that.

      $ git commit -m 'initial commit'$ git add forgotten_file$ git commit --amend    
      • Eventually you will only have one commit-the second commit will replace the result of the first commit.
2. Cancel the staged file
  • The next two subsections show how to manipulate the files that have been modified in the staging area and working directory. These commands, while modifying the state of the file, also prompt how to undo the operation.

  • For example, you have modified two files and want to commit them as two independent modifications, but accidentally entered git add * two of them. How do I cancel only one of the two staged storage? git statusthe command prompts you.

    $ git add *$ git statusOn branch masterChanges to be committed:  (use "git reset HEAD <file>..." to unstage)    renamed:    README.md -> README    modified:   CONTRIBUTING.md
  • Just below the text "Changes to be committed", you are prompted git reset HEAD <file>... to use to cancel the staging. So we can cancel the staging of the Contributing.md file.

    # git reset HEAD [文件名]$ git reset HEAD CONTRIBUTING.md
    Unstaged changes after reset:M   CONTRIBUTING.md$ git statusOn branch masterChanges to be committed:  (use "git reset HEAD <file>..." to unstage)    renamed:    README.md -> READMEChanges not staged for commit:  (use "git add <file>..." to update what will be committed)  (use "git checkout -- <file>..." to discard changes in working directory)    modified:   CONTRIBUTING.md
  • Although adding an option at the time of the call --hard can make git reset a dangerous command (which could cause all current progress in the working directory to be lost!). ), but the files in the working directory in this example are not modified. Calling without an option git reset is not dangerous-it only modifies the staging area.

3, undo the modification of the file
    • What if you don't want to keep the changes to the Contributing.md file? How can you easily undo the modification-restore it to the last commit (or just clone it, or just put it in the working directory)? Fortunately, git status It also tells you how to do it. In the last example, there is no staging area.

      Changes not staged for commit:  (use "git add <file>..." to update what will be committed)  (use "git checkout -- <file>..." to discard changes in working directory)    modified:   CONTRIBUTING.md    
    • It tells you very clearly how to undo the changes you have made before.

      # git checkout -- [文件名]$ git checkout -- CONTRIBUTING.md
      $ git statusOn branch masterChanges to be committed:  (use "git reset HEAD <file>..." to unstage)    renamed:    README.md -> README
    • git checkout -- [file]is a dangerous command. Any changes you make to that file will disappear-you just copy another file to overwrite it. Don't use this command unless you really know that you don't want the file.

Ios-git Undo operation (Distributed version control system)

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.