github - Git 问题, 一个 master, 多个新功能分支, 怎样有序地合并和提交?
怪我咯
怪我咯 2017-04-21 11:18:40
0
3
672

以前大多个是一个的使用 Git, 到 Github 上提交的场景, 对多人开发合并项目经验不多,
现在遇到的是在 Github 上存在主分支, 本地需要修改多个功能和 bug 等等,
我是按以前实习回来的同学提示, 在多个分支开发不同的功能, 然后合并提交..
合并和提交的顺序不是确定的, 因此不能简单直接用 merge 每次一个个叠加.
有时我用 rebase, 但有发现 commit 顺序不是时间顺序, 到线上被 merge 以后也不是非常清晰
于是我想问一下面对这样的场景, 用怎样的方式管理会更合适?

有在 Google, 但一些细节不清晰.. 比如 commit 显示顺序.. 还有再次被 merge 后的细节..

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(3)
大家讲道理

Git supports many kinds of workflows. The one we usually use is this. Create a main branch remotely and create functional branches locally. The daily workflow is as follows:

Go to your own working branch
$ git checkout work

Work
....

Submit changes to the working branch
$ git commit -a

Back to the main branch
$ git checkout master

Get the latest remote modifications, no conflicts will occur at this time
$ git pull

Back to the working branch
$ git checkout work

Use rebase to merge the modifications to the main trunk. If there are conflicts, resolve them at this time
$ git rebase master

Back to the main branch
$ git checkout master

Merge the modifications of the working branch without conflicts at this time.
$ git merge work

Commit to remote trunk
$ git push

The advantage of this is that the history on the remote trunk is always linear. Everyone resolves conflicts on their local branch and does not create conflicts on the trunk.

洪涛

The answer given by the friend above is very good. I will add one more information here for the poster’s reference. This was written by Brother Ruan, [git branch management strategy](http://www.ruanyifeng.com/blog/2012/0...).

阿神

You can develop together on a branch. When you make changes, use

before submitting.
git stash

In this way, all local modifications are cached in a stack, and then other people’s modifications are synchronized

git pull --rebase

The next step is to restore your changes to the latest node

git stash pop

Then use git commit to submit, so that the version of a branch will continue to develop in order, rather than like knitting a sweater. You can take a look at the comparison chart before and after we use this method

Before:

After

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template