git use tutorial (v)--git rewrite history

Source: Internet
Author: User

1. Git commit–amend

If you just want to modify the commit you just submitted (the last commit), you can use to git commit --amend modify the last commit. Use this command to pop up a dialog box (under Windows) or the Vim editing interface (under Linux). In the pop-up interface to make changes, save can be submitted with the new submission information. This command can only modify the submission memo information and cannot be modified for other information.

2. Git reset–soft head^

The command rolls back the last commit and executes once to rollback the most recent commit. The changes are then entered into the staging area and can be used git commit -m to continue the submission.

3. Git rebase

The above two commands are for the most recent commit, what if you want to modify more than one commit at a time? git rebase -i 提交号(all submissions after the submission number has been modified) or git rebase -i HEAD~3 (modified the last three submissions). When this command is used, the commit information for all commits that need to be modified is listed in chronological order. Examples are as follows:

Pick52e5Cd9. Test1pick theDfaf3. Test2pick d178473. test3# Rebase 080e4be. d178473 onto 080e4be## Commands:# p, pick = use commit# r, reword = use commit, but edit the commit message# E, edit = use commit, but stop for amending# s, squash = use commit, but meld to previous commit# f, fixup = like "squash", but discard this commit ' s log message# x, exec = Run command (the rest of the line) using Shell## These lines can be re-ordered; they is executed from top to bottom.## If You remove a line here, COMMIT would be LOST.## However, if you remove everything, the rebase would be aborted.## Note that empty commits is commented out

We just need to edit this script, and Git provides 6 commands, as follows:

    • P (pick): Use commit (Default)
    • R (Reword): using commit, but to modify the commit information (using R's commit, after saving and exiting the script will be followed by the interface to modify each commit information)
    • E (Edit): Use Commit, but interrupt let user modify, at terminal can use git commit --amend to modify
    • S (squash): Compresses the current commit and the previous commit into a single commit, and the merged submission uses the author information of the previous submission
    • F (Fixup): Compresses the current commit and the previous commit into a single commit and discards the current commit information, using the previous commit information
    • X (EXEC): a command statement that needs to be executed when the commit is processed
4. Git filter-branch

This command can modify all commits to the repository and is very powerful. such as bulk modification of the submitter's information, such as the modification of all the submitter to Zhangsan submission information for Gavincook, the mailbox is [email protected], we can use the following command:

‘    if"$GIT_AUTHOR_NAME""zhangsan" ];     then        GIT_AUTHOR_NAME="GavinCook";        GIT_AUTHOR_EMAIL="[email protected]";        "[email protected]";    else         "[email protected]";    fi‘ HEAD

Git provides a lot of filter types, and more examples are: examples

git use tutorial (v)--git rewrite history

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.