Git Undo Commit Considerations

Source: Internet
Author: User

Git undo commit operation command git reset--hard head^

First, new three files, Demo1,demo2,demo3

Second, git add command to staging area, git reset HEAD demo1 is the file submitted to staging area revocation.

, executing git reset HEAD demo1 will remove demo1 from staging area and is now untracked.

Third, Git commit commits the local repository

, Git commit commits the DEMO2,DEMO3 to the local repository.

Four, now want to undo the previous commit, you can use the git reset--hard head^ command

In the third step, commit demo2, then commit DEMO3, so now the head is the commit value of DEMO3.

(Head is pointing to the latest commit, last Commit is head^, previous is head^^, can also be written as head~2, and so on)

So git reset--hard HEAD is to undo the latest commit Demo3, Undo is very thorough and local files will be deleted.

Now run the LS command and you will find: The Demo3 file is no longer available.

Git Undo Commit Considerations

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.