Git modification submission instructions

Source: Internet
Author: User

Refer to self-Pro git. Measure the test taker's knowledge about rebase operations and how to rearrange the rebase.

Modify Multiple submission instructions

To modify the submission earlier in the history, you must use more complex tools. Git does not have a tool to modify the history, but you can use the rebase tool to extract the Integration Series and submit them to their original head instead of moving them to the new
. With this interactive rebase tool, you can stay after each commit if you want to modify or change the description, add files, or anything else. You can run it interactively by adding the-I option to git rebase.
Rebase. You must specify the tracing depth of the submission that you want to rewrite by telling the command about the submission to which the command is derived.
For example, if you want to modify the description of the last three submissions, or any of them, you must provide a parameter to git rebase-I to specify the parent commit you want to modify, for example, head ~ 2 or head ~ 3. May remember ~ 3 more
Easy, because you want to modify the last three submissions, but remember that you actually referred to the parent commit that you want to modify before the four commits.

$ git rebase -i HEAD~3

Remind me that this is an authorization command -- head ~ 3. Each submission within the head range will be overwritten, regardless of whether you modify the description. Do not cover the submissions that you have pushed to the central server (I understand: Do not use this rebase command for pushed submissions)-this will cause confusion for other developers, because you provide different versions of the same change.
Run this command to provide a submission list for your text editor. It looks like the following:

pick f7f3f6d changed my name a bitpick 310154e updated README formatting and added blamepick a5f4a0d added cat-file# Rebase 710f0f8..a5f4a0d onto 710f0f8## Commands:# p, pick = use commit# e, edit = use commit, but stop for amending# s, squash = use commit, but meld into previous commit## If you remove a line here THAT COMMIT WILL BE LOST.# However, if you remove everything, the rebase will be aborted.

It is important to note that the order of these submissions is different from what you usually see through the log command. If you run log, you will see the following results:

$ git log --pretty=format:"%h %s" HEAD~3..HEADa5f4a0d added cat-file310154e updated README formatting and added blamef7f3f6d changed my name a bit

Note the reverse order here. The interactive rebase provides you with a script to be run. It starts from the submission you specify on the command line (Head ~ 3) replay the changes introduced in each submission from top to bottom. It puts the earliest column on top rather than the nearest one, because this is the first one to be replayed.
You need to modify this script so that it stays on the change you want to modify. To do this, you only need to change the pick before each commit you want to modify to edit. For example, if you only want to modify the description for the third submission

Modify file:

Note the usage of nano editor ^ h indicates Ctrl + H

edit f7f3f6d changed my name a bitpick 310154e updated README formatting and added blamepick a5f4a0d added cat-file

When you save and exit the editor, git returns to the last commit in the list and sends you to the command line. The following information is displayed:

$ git rebase -i HEAD~3Stopped at 7482e0d... updated the gemspec to hopefully work betterYou can amend the commit now, withgit commit --amendOnce you’re satisfied with your changes, rungit rebase --continue

These instructions clearly tell you what to do. Input

$ git commit --amend

Modify the submission instructions and exit the editor. Then, run

$ git rebase --continue

This command will automatically apply the other two commits and you will complete the task. If you change the pick of more rows to edit, you can repeat these steps for the Submission you want to modify. Git stops every time and allows you to correct and submit the changes.
Continue running.

Reschedule submission

You can also use the interactive derivation to completely rearrange or delete the submission. If you want to delete the "added cat-file" submission and modify the order in which the other two submissions are introduced

pick f7f3f6d changed my name a bitpick 310154e updated README formatting and added blamepick a5f4a0d added cat-fil

Change to this:

pick 310154e updated README formatting and added blamepick f7f3f6d changed my name a bit

When you save and exit the editor, git reverts the branch back to the parent commit of these commits, applies 310154e, f7f3f6d, and then stops. You have modified the submission order effectively and permanently deleted the "added cat-file" commit.

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.