更改 git 中分支的根目录
我正在使用 git 并且想要更改现有分支的基础。这是由部署系统引起的,该系统将该显式分支拉入我的生产环境。在规划我的发布时,我每次想要上线时都会创建一个标签。但我的分支也有特殊的更改,因此 git reset --hard v1.0 不起作用。
这是一个小例子。我希望它
C---D---E deploy
/
A---B---F---G master
\
v1.0
变成这样
C---D---E deploy
/
A---B---F---G---H---I---J---K master
\ \
v1.0 v1.1
也许 git rebase 是我正在寻找的,但手册页对我没有帮助。感谢您的回复!
I'm using git and want to change the base of an exiting branch. This is caused by a deployment system, which pulls this explicit branch into my production environment. When planning my releases, I create a tag every time I want to go live. But my branch has special changes too, so git reset --hard v1.0
won't work.
Here a small example. I want this
C---D---E deploy
/
A---B---F---G master
\
v1.0
to become this
C---D---E deploy
/
A---B---F---G---H---I---J---K master
\ \
v1.0 v1.1
Maybe git rebase
is what I am looking for, but the man pages don't help me. Thanks for your replies!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
git rebase
应该像你说的那样,允许你更改部署的基础:但你最终会得到
也就是说,
deploy
分支的提交部分的SHA1被重写,如果没有人克隆说deploy
,这也不算太糟糕> 分支并正在研究它。由于它是用于部署的分支,因此很可能是这种情况(即没有人在该分支的克隆上工作)。
git rebase
should, like you say, allow you to change the base of deploy:But you will end up with
That is, the SHA1 of the commits part of
deploy
branch are rewritten, which isn't too bad if nobody cloned saiddeploy
branch and was working on it.Since it is a branch for deployment, that is most likely the case (i.e. nobody was working on a clone of said branch).
是的,可以使用rebase来达到想要的效果。以下命令将签出
deploy
分支并重播其所有提交,这些提交无法通过v1.1
访问,位于v1.1
之上:(详细的方法是:
git rebase --onto v1.1 v1.0 deploy
)但是为什么要重新设置基础并更改历史记录呢?您可以简单地将开发主线更改为您的部署分支:
这将使您的所有提交哈希保持不变,您的历史记录将如下所示(
M
是合并提交):因为在变基以及合并期间,在使用基于合并的方法时,您将有合并冲突的历史记录。使用变基,您就不会在变基操作期间发生冲突的历史记录。使用基于合并的工作流程,您稍后可以在合并提交的(组合)差异中看到冲突。
yes, you can use rebase to achieve the desired effect. the following command will checkout the
deploy
branch and replay all its commits, which are not reachable throughv1.1
, on top ofv1.1
:(the verbose way would be:
git rebase --onto v1.1 v1.0 deploy
)but why rebasing and altering history? you can simply change the mainline of development into your deployment-branch:
this will leave all your commit hashes intact, your history will then look like this (
M
being the merge commit):since conflicts might arise during rebase as well as during merge, you will have a history of merge conflicts when using the merge based approach. with rebase you don't have a history of conflicts which happened during rebase operation. using a merge based workflow, you can later see your conflicts in the (combined) diff of the merge commits.
我不明白你为什么想失去原来的分支。在这种情况下我会做什么:
编辑:添加架构
你最终会得到类似的结果
I don't understand why you'd want to lose your original branch. What I would do in such a case:
EDIT: added schema
You'll end up with something like that
git rebase 应该适合你:
或者
看看 http://progit.org/book/ch3 -6.html - 我认为应该可以帮助你更好地理解 rebase
git rebase should work for you:
or
Have a look at http://progit.org/book/ch3-6.html - should help you understand rebase better I think