Getting Started with Git (4. Submission and history)

Source: Internet
Author: User

Iv. Submission and history

Understand the status of the file, we have made the necessary changes to the file, we will put the changes we made into the repository, so we can restore to the current version when needed, and to revert to a version, it is generally necessary to view the history of the version.

Submit

Submission is straightforward and executes "git commit" directly. Git commit will call the default or we set the compiler to fill in the instructions, but the submission instructions are best to git requirements: the first line to fill in a simple description, separate line to fill in the detailed instructions. Because the first row will be extracted in some cases, such as reviewing short commit history or submitting patches to others, the number of characters should not be too much, 40 is good. See the commit history below.

View commit History

View the commands used for the commit history

650) this.width=650; "class=" Confluence-embedded-image "src=" http://wiki.sankuai.com/download/attachments/ 333188871/image2015-8-18%2010%3a17%3a53.png?version=1&modificationdate=1439868920000&api=v2 "Style=" margin:0px 2px;padding:0px;border:0px; "alt=" Image2015-8-18%2010%3a17%3a53.png?versio "/>

, showing the author, author mailbox, submission instructions and commit time, "git log" can be used to put multiple parameters, such as:

650) this.width=650; "class=" Confluence-embedded-image "src=" http://wiki.sankuai.com/download/attachments/ 333188871/image2015-8-18%2010%3a18%3a9.png?version=1&modificationdate=1439868920000&api=v2 "Style=" margin:0px 2px;padding:0px;border:0px; "alt=" Image2015-8-18%2010%3a18%3a9.png?version "/>

Displays only the latest 1 logs, denoted by "-N".

650) this.width=650; "class=" Confluence-embedded-image "src=" http://wiki.sankuai.com/download/attachments/ 333188871/image2015-8-18%2010%3a18%3a24.png?version=1&modificationdate=1439868920000&api=v2 "Style=" margin:0px 2px;padding:0px;border:0px; "alt=" Image2015-8-18%2010%3a18%3a24.png?versio "/>

Showing simple SHA-1 values and simple commit instructions, Oneline only shows the first line of the submission instructions, so the first line shows that the best simple point is easier to display on one line.

"Git log--graph" graphically displays the relationship of the commit history, which makes it easy to see the branching information of the commit history, and of course the graphics that the console uses to draw the characters.

More parameters for "git log" can be viewed with command help.

Commits that are not staged

If we want to skip staging area directly commit the modified file, you can use the "-a" parameter, but be cautious, don't accidentally submit the file you do not want to submit

Git commit-a

If you need to fill in the submission instructions quickly, you can use the "-m" parameter

Git commit-m ' commit message '

Revised submissions

If we find that a file has been changed incorrectly after submission, or just want to modify the submission instructions, you can make changes to the corresponding file, add the modified file through "git add" to staging area, and then execute the following command:

git commit--amend

The commit description is then modified to overwrite the last commit, but only the last commit can be overridden.

Rearrange commits

By using the rebase, you can modify the description of multiple submissions and rearrange the commit history, split, merge commits, and about rebase when it comes to branching, let's take a look at the Reflow commit.

Let's say our commit history is this:

650) this.width=650; "class=" Confluence-embedded-image "height=" "src=" http://wiki.sankuai.com/download/ Attachments/333188871/image2015-8-18%2010%3a30%3a47.png?version=1&modificationdate=1439868920000&api= V2 "style=" margin:0px 2px;padding:0px;border:0px; alt= " Image2015-8-18%2010%3a30%3a47.png?versio"/>

if we want to rearrange the commit history of the last two commits, we can use the Interactive rebase command:  

git rebase-i head~2 or git rebase-i 3366e1123010e7d67620ff86040a061ae76de0c8

Head~2 represents the third-to-last commit, which specifies the parent commit of the oldest commit to Reflow, where second commit and third commit are to be re-ordered, so you specify the commit ID of the initial commit. :

650) this.width=650; "class=" Confluence-embedded-image "height=" "src=" http://wiki.sankuai.com/download/ Attachments/333188871/image2015-8-18%2010%3a31%3a11.png?version=1&modificationdate=1439868920000&api= V2 "style=" margin:0px 2px;padding:0px;border:0px; alt= " Image2015-8-18%2010%3a31%3a11.png?versio"/>

The comments section details the role of each option, and if we want to interact with both commits, simply swap the first two lines in the next position on the OK, swap the position after saving and then look at the commit history:

650) this.width=650; "class=" Confluence-embedded-image "height=" "src=" http://wiki.sankuai.com/download/ Attachments/333188871/image2015-8-18%2010%3a31%3a23.png?version=1&modificationdate=1439868920000&api= V2 "style=" margin:0px 2px;padding:0px;border:0px; alt= " Image2015-8-18%2010%3a31%3a23.png?versio"/>

You can see that the commit history has changed, and the latest commit IDs for the two commits have changed, so don't use this command if the commits have been push to the remote server.

Delete Commit and modify submission instructions

If you want to delete a commit, you only need to delete the corresponding line, and to modify the submission instructions for a submission, you need to change the pick of the corresponding line to reward.

Merge Submit-squashing

The merge submission is also very simple, from the note in the description, only need to change the corresponding line of the pick to squash can be submitted to the whole and the submission of its previous row.

Splitting commits

As for splitting commits, since git can't know where you're going to split a commit, we need to let git stop at the point where it needs to be split, manually modify the commit, and then change the pick to edit so that git will stop when it handles the commit. At this point we can make the appropriate changes and submit them multiple times to split the commits.

Revoke a submission

The previous method of deleting commits, but if it is a multi-person cooperation, if a commit has been push to the remote repository, it is not possible to delete the submission in that way, it is necessary to revoke the submission

git revert <commit-id>

This command rolls back all changes to the specified commit and generates a new commit at the same time.

Reset

Git reset modifies the head to the specified state and uses the

git reset [options] <commit>

This command causes head to make a specified commit, typically using 3 parameters, 3 of which affect changes in the workspace and staging area:

--soft: Change the state of the head only, without changing the contents of the workspace and staging area

--mixed (default): Undo Staging Area changes, staging area changes are transferred to the workspace

--hard: Undo changes to Workspace and staging area

Cherry-pick

When working with others and doing development, you will be able to contribute code to others or receive contributions from others, sometimes you may not want to completely merge other people's contribution code, just want one of the commits, then you can use Cherry-pick. Just one command.

Git Cherry-pick <commit-id>

Filter-branch

This command modifies the entire history, such as deleting a file-related information from all history and changing the e-mail address globally.


Getting Started with Git (4. Submission and 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.