1

我与许多开发人员一起在几个项目中使用 git。我通常的工作流程是针对特定功能/请求在本地分支,将我的更改合并到上游跟踪的本地分支作为快进合并,然后推送更改。我总是为一个单一的提交分支。我从来没有在我与其他人共享的分支上进行本地提交,所以我可以自由地在本地进行 rebase/muck,直到我将我的更改推送到上游。作为一个偏好问题,我喜欢我的合并尽可能快进提交。例如,如果一个项目的版本 1 的所有内容都由origin/v1分支上的所有开发人员推送,我会:

git checkout v1
git checkout -b feature-A
#Do work on feature-A branch.  Test, rebase --interactive to clean up

最终,我想将我的更改合并到v1本地并推送到origin/v1. 我会签出git fetch originfeature-A。如果进行更改,我将结帐v1并合并

git fetch origin
#If New changes are present checkout v1 and merge
git checkout v1
git merge origin/v1 #I could pull but I prefer to fetch, log origin/v1, and then merge

现在为feature-AI checkout feature-A、rebase to v1、checkout v1、mergefeature-A和 push v1back实现快进合并origin

git checkout feature-A
git rebase v1
git checkout v1
git merge --ff-only feature-A
git push origin v1

非快进提交没有错,合并提交也没有错。同样,这只是一个偏好问题。我想知道是否有更好的工作流程来完成同样的事情,而无需通过所有分支机构的结帐。可能有一个我不知道的 git 命令在我在更新的分支feature-A之上重新设置基础后会起作用。v1

https://stackoverflow.com/a/4157106/620304看起来可能会有所帮助。一个可能的工作流程是在我 rebase 后v1使用来自 origin 的最新更改进行更新并更新v1到本地的 HEAD :feature-A

#Starting from feature-A currently checked out
git fetch origin
#New changes are present
git checkout v1
git merge origin/v1
git checkout feature-A
#In I didn't fetch anything from origin's v1 branch I can skip the commands between the comments
git rebase v1
git branch -f v1 feature-A
git push origin v1

我确信可能有更好的方法。非常感谢任何帮助/输入。

4

1 回答 1

4

A workflow that uses only fast-forward merges is essentially a rebase workflow. The general rebase workflow works very similar to the example you gave, except for git rebase origin/v1 instead of merging.

The most referenced article I've seen is Randy Fay's blog post: A Rebase Workflow for Git.

Be sure to read the follow-up article, linked at the start of this one, for some short-cuts to make it easy to use.

于 2013-02-26T20:10:35.597 回答