【发布时间】:2013-11-13 17:41:36
【问题描述】:
我正在尝试使用 Git 分支,以便从 master 中创建功能,但我经常会弄乱我的 git 存储库:/
我在 Stack Overflow 上搜索了我想要实现的目标,通常我可以找到如何合并/分支/还原/等,但在我面临的工作流程中却找不到,这对我来说,会发生什么经常。
这是我作为工作流程要做的事情:
- 在 master 上有一个基础项目
- 创建一个新分支并在其上工作(创建/修改、提交、推送)
- 返回 master(或其他分支)并应用一些修改(紧急错误修复)
- 将这些更改从 master 合并到我当前的工作分支中(以减少冲突问题)
- 完成后,将我的分支合并到 master,准备部署!
其中一些操作似乎很容易,但中间部分(切换回、掌握、应用更改然后再次转到分支)对我来说似乎是不可能的:/
这就是我所在的位置:
(假设项目已经在git上,部分工作已经推送给master)
git branch feature
git checkout feature
# do some add/edit, commit, push on that branch
# Now I need to fix a bug in master :
git checkout master
# how can I get my files in the master state ?
# My best guest so far :
git revert HEAD
# do some add/edit, commit, push on master
# Finished to fix the bug, going back to continue my feature :
git checkout feature
# Again, how can I get my files to match the current state of the branch feature ?
git revert HEAD # And git asks me about a revert ? what ? I'm lost :/
# getting the recent changes from master into feature, in order to avoid later conflicts
# This can also be made often if you work with others
git fetch origin
git rebase origin/feature
git rebase origin/master
# do some add/edit, commit, push on master
# And when you have finish, merge feature into master :
git checkout master
git pull origin master
git merge feature
git branch -d feature # if you want to remove it.
这是我当前假定的工作流程,但我不确定 revert HEAD 是一个好的解决方案,当我返回时,Git 更加证实了这一点,它要求我恢复到我之前的状态推(?!)。
有人可以帮助我澄清我的情况和/或指导我做一个很好的(但请非常简单)解释来做我正在尝试的事情吗?
非常感谢,非常感谢!
【问题讨论】:
标签: git git-branch git-merge