git branch commonly used techniques

Git branch branch as a powerful, in the normal development if we can put to good use, will be able to exponentially enhance the development efficiency.

1. branch development model

The main branch of masterthe generally stable version, need to ensure that at all times publish.

So, you can create a development branch for the development of new features.

git branch dev

See what branch

git branch -a
* dev
  master
  bugfix-1
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/dev
  remotes/source/master

To see what the local branch

git branch
* dev
  master
  bugfix-1

To see what remote branch

git branch -r
  origin/HEAD -> origin/master
  origin/master
  origin/dev
  source/master

When developing a new feature on the branch has been developed and tested OK, this time, can be incorporated into master.

The current in masterthe branch, using the following command to merge:

git merge dev --no-ff -m "AI2.0开发完成"

It is strongly recommended the use of --no-ffoptions, so that when merged into the master branch, you will generate a commit record.

If you need to roll back the merged into the master branch, just submitted directly to record the time of the merger, to be rolled back.

Especially when the main branch and the dev branch cross submit records, if you do not use the --no-ff, you need one by one to find which recording is submitted on dev branch, would be more trouble.

By default, Git performed "fast forward merge formula" (fast-farward merge), Master branch directly to branch point Develop.

Two kinds of combined embodiment as shown in FIG.

2. The difference between the two branches

Submitted a lot of content on the development branch, this time, if you need to compare differences in the development of the branch and the main branch, you can use the following method:

2.1 Viewing file differences in two branches

git diff branch1 branch2 --stat

For example, see the devbranch with respect to masterchanges to the file:

git diff master dev  --stat

2.2 view the contents of specific differences of the two branches

git diff branch1 branch2

3. View commit history and the consolidation of branch

When used in conjunction with --graph oneline or format option, you can see the beginning of more than a simple graphical representation of some ASCII strings, vividly demonstrated the differentiation of each branch and rebase submit resides.

git log --pretty=oneline --graph
*   7880521e21b1329965179bd45d632a3c91e227fa (HEAD -> master) Merge branch 'dev'
|\
| * 27cc24423ba0fcb01365eb7ffdc9ed33b059c36b (dev) 3 test
| * 714788192eb4760b614c2ab5fe45634df89904ee 2 test
* | ccce2c06660d8263e6a65d124ab947db0be56556 2 txt
|/
* 24c3941c7f5ef3e6b0c0be7638d29387f4643d90 1 test
git log --pretty=format:"%h %s" --graph
*   7880521 Merge branch 'dev'
|\
| * 27cc244 3 test
| * 7147881 2 test
* | ccce2c0 2 txt
|/
* 24c3941 1 test
(END)

*In which branch representatives are submitted.

4. Reference

git commit history
git branch management strategy

Guess you like

Origin www.cnblogs.com/lanyangsh/p/10988924.html