GIT usage Specification Process Summary _ Related tips

Source: Internet
Author: User
Tags commit ticket openpgp

The following is the Thoughtbot git usage specification process. I've learned a lot from it and recommended that you use Git as well.

First Step: New branch

First, each time you develop a new feature, you should create a separate branch.

# Get skeleton Latest code
$ git checkout master
$ git Pull
# Create a new development branch Myfeature
$ git checkout-b myfeature

Step two: Commit the Branch commit

After the branch has been modified, it can be submitted commit .

$ git add--all
$ git status
$ git commit--verbose

git addThe all parameter of the command, which indicates that all changes are saved (including new, modified, and deleted). Starting with Git 2.0, all is git add the default parameter, so you can also use git add .

git statuscommand, which is used to view files that have changed.

git commit parameter of the command verbose , the result of the diff is listed.

Step Three: Write submission information

commitwhen submitting, you must give a complete summary of the submission information, below is a template.

Present-tense Summary under Characters

* More information about commit (under characters).
* More information about commit (under characters).

Http://project.management-system.com/ticket/123
The first line is a feed of no more than 50 words, and then a blank line, listing the reasons for the changes, major changes, and issues to be noted. Finally, provide the corresponding URL (such as Bug ticket).

Fourth step: synchronizing with the backbone

In the development of a branch, always keep in sync with the backbone.

$ GIT fetch origin
$ git rebase origin/master

Fifth Step: Merge Commit

After branching development, it is likely to have a bunch commit , but when merged into the backbone, it is often expected to have only one (or up to two or three), which is commit not only clear but also manageable.

So how do you combine multiple commit ? It's going to take a git rebase command.

$ git rebase-i origin/master

git rebaseThe command's I parameter represents an interaction (interactive), at which point Git opens an interactive interface for the next steps.

Here's an example of Tute Costa to explain how to merge commit .

Pick 07c5abd introduce OpenPGP and teach basic usage pick
Fix de9b1eb::P postchecker ost#urls pick
Hey 3e7ee36 , stop all the highlighting
pick fa20af3 git interactive rebase, squash, amend
# rebase 8db7e8b. Fa20af3 onto 8db7e8b
#
Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit me Ssage
# E, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
   
    # F, fixup = like "squash", but discard this commit ' s log message
# x, exec = Run command (the rest of the line) USI ng Shell
# These
lines can is re-ordered they are executed from top to bottom.
#
If You remove a line here, that COMMIT would be LOST.
#
However, if you remove everything, the rebase would be aborted.
#
# That's empty commits are commented out #
   

The interactive interface above lists the latest 4 of the current branch commit (the newer the next). Each commit front has an action command, which, by default pick , means that the row commit is selected for rebase operation.

4 commit Below is a bunch of annotations that list the commands you can use.

pick: Normal selection

Reword: Select, and modify the submission information;

edit: checked, rebase will be paused, allowing you to modify this commit (refer to here)

squash: checked to merge the current commit with the previous commit

fixup: same as squash, but does not save submit information for current commit

exec: execute other shell commands

The above 6 commands, squash and fixup can be used for merging commit . First commit , change the verb (s) that need to be merged squash .

Pick 07c5abd introduce OpenPGP and teach basic usage
s de9b1eb Fix postchecker::P ost#urls
s 3e7ee36 Hey Kids, stop All the highlighting
pick fa20af3 git interactive rebase, squash, amend

This change, after execution, the current branch will only have two left commit . The second and third lines are commit merged into the first row commit . The submission information will also contain the three commit submissions.

# This is a combination of 3 commits.
# the "the" the "the" "s" is:
introduce OpenPGP and teach basic usage
# The 2nd commits:
Fix postchecker::P ost#urls
# The 3rd commit message: "
Hey kids, stop all" highlighting

If you change the command of the third row to a squash fixup command.

Pick 07c5abd introduce OpenPGP and teach basic usage
s de9b1eb Fix postchecker::P ost#urls
F 3e7ee36 Hey Kids, stop All the highlighting
pick fa20af3 git interactive rebase, squash, amend

The run results are the same, or two commit , the second and third lines commit are merged into the first row commit . However, in the new submission, the third line commit of submissions will be commented out.

# This is a combination of 3 commits.
# the "the" the "the" "s" is:
introduce OpenPGP and teach basic usage
# The 2nd commits:
Fix postchecker::P ost#urls
# The 3rd commit:
# Hey Kids, stop all the highlighting

squashand fixup commands, which can also be used as command-line arguments, and are automatically merged commit .

$ git commit--fixup 
$ git rebase-i--autosquash

This usage please refer to this article, here is not explained.

Step sixth: push to remote warehouse

commitafter merging, you can push the current branch to the remote repository.

$ git push--force origin myfeature

git pushcommand to add force parameters, because rebase later, the branch history has changed, and the remote branch is not necessarily compatible, there may be forced to push (see here).

Seventh step: Issue Pull request

After committing to a remote warehouse, you can send it Pull Request to the master branch and then request someone else to do the code to confirm that it review can be merged into master .

Summarize

The above is the entire content of this article, I hope to be able to learn or work to bring certain help, if there is doubt you can message exchange.

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.