Git usage standard process
In team development, it is very important to follow a reasonable and clear Git use process.
Otherwise, everyone submits a bunch of messy commit, and the project will soon become difficult to coordinate and maintain.
The following describes the standard Git usage process of ThoughtBot. I have learned a lot and I recommend you use Git as well.
Step 1: Create a branch
First, you should create a new branch for each new function development (For details, refer to Git branch management policy).
# Get the latest code of the trunk $ git checkout master $ git pull # Create a New Development Branch myfeature $ git checkout-B myfeature
Step 2: Submit the branch commit
After modifying the branch, you can submit commit.
$ git add --all$ git status$ git commit --verbose
The all parameter of the git add command stores all changes (including new, modified, and deleted ). From Git 2.0, all is the default parameter of git add, so you can also use git add.
The git status command is used to view the changed files.
The verbose parameter of the git commit command lists the diff results.
Step 3: Write the submitted information
When submitting a commit, you must provide the complete and brief submission information. The following is a template.
Present-tense summary under 50 characters* More information about commit (under 72 characters).* More information about commit (under 72 characters).http://project.management-system.com/ticket/123
The first line is a summary with no more than 50 characters, and a blank line lists the reasons for the change, major changes, and issues needing attention. Finally, provide the corresponding URL (such as Bug ticket ).
Step 4: synchronize with the master
During the branch development process, it is often necessary to maintain synchronization with the trunk.
$ git fetch origin$ git rebase origin/master
Step 5: Merge commit
After branch development is complete, there may be a bunch of commit, but when merged to the trunk, you often want only one (or up to two or three) commit, which is clear and easy to manage.
So how can we merge multiple commit statements? This requires the git rebase command.
$ git rebase -i origin/master
The I parameter of the git rebase command indicates interactive. In this case, git opens an interactive interface and performs the next step.
The following example uses Tute Costa to explain how to merge commit.
pick 07c5abd Introduce OpenPGP and teach basic usagepick de9b1eb Fix PostChecker::Post#urlspick 3e7ee36 Hey kids, stop all the highlightingpick fa20af3 git interactive rebase, squash, amend# Rebase 8db7e8b..fa20af3 onto 8db7e8b## 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 into 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 are executed from top to bottom.## If you remove a line here THAT COMMIT WILL BE LOST.## However, if you remove everything, the rebase will be aborted.## Note that empty commits are commented out
In the preceding interactive interface, the latest four commit entries of the current branch are listed (the newer the next one ). Each commit is preceded by an operation command. The default value is pick, indicating that the row commit is selected and rebase is required.
Below are a lot of comments for the four commit, listing the commands that can be used.
- Pick: Selected normally
- Reword: select and modify the submission information;
- Edit: Selected. rebase is paused. You can modify the commit (refer to here)
- Squash: selected. The current commit and the previous commit are merged.
- Fixup: Same as squash, but does not save the submission information of the current commit.
- Exec: execute other shell commands
Among the above six commands, squash and fixup can be used to merge commit. First, change the verb before the commit to squash (or s ).
pick 07c5abd Introduce OpenPGP and teach basic usages de9b1eb Fix PostChecker::Post#urlss 3e7ee36 Hey kids, stop all the highlightingpick fa20af3 git interactive rebase, squash, amend
In this way, after execution, only two commit entries are left in the current branch. The commit of the second and third rows will be merged into the commit of the first row. The submission information will also contain the submission information of the three commit.
# This is a combination of 3 commits.# The first commit's message is:Introduce OpenPGP and teach basic usage# This is the 2nd commit message:Fix PostChecker::Post#urls# This is the 3rd commit message:Hey kids, stop all the highlighting
If you change the squash command of the third line to the fixup command.
pick 07c5abd Introduce OpenPGP and teach basic usages de9b1eb Fix PostChecker::Post#urlsf 3e7ee36 Hey kids, stop all the highlightingpick fa20af3 git interactive rebase, squash, amend
If the running result is the same, two commit statements are generated, And the commit statements of the second and third rows are merged to the commit statement of the first row. However, in the new commit information, the commit information of the third line of commit will be commented out.
# This is a combination of 3 commits.# The first commit's message is:Introduce OpenPGP and teach basic usage# This is the 2nd commit message:Fix PostChecker::Post#urls# This is the 3rd commit message:# Hey kids, stop all the highlighting
Pony Foo proposes another simple method to merge commit, that is, to undo the last five commit and then create a new one.
$ git reset HEAD~5$ git add .$ git commit -am "Here's the bug fix that closes #28"$ git push --force
Squash and fixup commands can also be used as command line parameters to automatically merge commit.
$ git commit --fixup $ git rebase -i --autosquash
For this usage, refer to this article and I will not explain it here.
Step 6: Push to remote warehouse
After merging commit, you can push the current branch to the remote repository.
$ git push --force origin myfeature
The force parameter must be added to the git push command, because after rebase, the branch history has changed, which is not necessarily compatible with the remote branch, and may be forced to push (see here ).
Step 7: Send a Pull Request
After being submitted to the remote warehouse, you can send a Pull Request to the master branch, and then Request someone else to review the code to confirm that the Request can be merged to the master.
(End)
GitHub Tutorials:
GitHub tutorials
Git tag management details
Git branch management
Git remote repository details
Git local Repository (Repository) Details
Git server setup and Client installation
Git Overview
Share practical GitHub tutorials
How to Build and use Git servers in Ubuntu
Git details: click here
Git: click here
This article permanently updates the link address: