Git usage: how to perform version rollback or modify committed commit, gitcommit

Source: Internet
Author: User
Tags how to use git

Git usage: how to perform version rollback or modify committed commit, gitcommit

During the development process, we often need to use version management tools. git is the most famous version software. It was born from Linus Torvalds, the father of linux. Today, I will share with you how to use git for version rollback and how to modify only committed commit. git will give you "regret ".

Version rollback git reset
What if you have already submitted code that you do not want to submit, or are rejected and resubmitted after submitting code to the gerrit server? This is what we need git reset. Enter the git warehouse to be rolled back, such as/packages/apps/DemoApp/. Run git log to view the committed commit and author information, as shown below:
<pre name="code" class="plain">commit 0a30864b4d07fedb16e120b6e204b71c17139df1Author: xiong_it<xiong_it@helloworld.com>Date:   Tue Mar 17 09:49:38 2015 +0800    modified by put a hdmi-in patch        Change-Id: I4fb420061c9937377a5fc09634fae27ddbd67510commit 31b138de2c3a6869cac13e082454d5a15e95f153Author: aaa <aaa@helloworld.com>Date:   Thu Nov 6 11:14:06 2014 +0800    PD#99387(99384): fix kernel panic during suspend by open wifi        Change-Id: I30d4769c0d4c8c4b440b1515fbcb44737287855d


 

From the above we can see that I am the last submitted person. Now I want to roll back to the previous version. How can I do this?
 
Git reset 31b138de2c3a6869cac13e042554d5a15e95f153 press enter, OK, get it done! This string is the commit of the previous version. Note: it is not a Change-Id!
Commit rollback

After submitting a comment, we find that the comment is not detailed enough. What should we do if we want to modify it?

This is git commit -- amend can help you! Go to the git warehouse where you want to modify the last commit, execute git commit -- amend, And the vi edit will pop up to allow you to modify the last commit, without using the vi movable step: short version of vim in Linux/Ubuntu. Do not forget to submit it. Otherwise, the modified commit is invalid. Okay, actually, I made such a mistake-I forgot to submit it again...

For more information, see http://blog.csdn.net/xiong_it/article/details/44338223,thank you !!

Reference: http://www.open-open.com/lib/view/open1405048177091.html

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.