我希望将远程分支与HEAD同步,以便在最终合并时不会出现问题。因此,我想尝试将HEAD更改拉入我的分支中,以查看它们之间的差异。
如何在Git中完成以下工作流程?
- 检出一个远程分支。
- 一旦检出,将HEAD的更改拉入其中。
- 对分支进行一些编辑
- 将分支推送回相同分支的远程版本(不影响HEAD)。
有关实现相同目标的更好工作流的任何提示都将非常有用。
这些都是比较基础的内容:
# make sure your notion of the remote is up to date
git fetch origin
# create and check out a branch, at the same place as the remote master branch
git checkout -b origin-master origin/master
# merge your local master
git merge master
# test, edit away, hack hack hack
git add ...
git commit ...
# push back to origin
git push origin origin-master:master
git checkout -b master-merging master
git fetch origin
git merge origin/master
# test, hack, commit, push...
git push origin master-merging:master
或者使用增量合并:
git checkout -b master-merging master
git fetch origin
git merge origin/master~20 # 20 commits before origin/master
# test, hack, commit
git merge origin/master~10 # 10 commits before origin/master
# test, hack, commit
git merge origin/master
# test, hack, commit, push...
[remote-name]-[branch-name]
,对吧?) - Cascabel