GIT重命名分支并保留所有提交历史记录 [英] GIT Renaming a branch and keeping all commit history

查看:192
本文介绍了GIT重命名分支并保留所有提交历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于在git中重命名分支的问题.我创建了本地分支dev并将分支推送到远程.我在dev分支上做了很多工作,并定期更新远程分支.

I have a question regarding renaming a branch in git. I created a local branch dev and pushed branch to remote. I did lots of work on the dev branch and am updating remote branch regularly.

现在,我想将分支的名称从dev更改为development.我知道如何在GIT中重命名分支.

Now I want to change the name of the branch from dev to development. I know how to rename a branch in GIT.

我的问题就像我重命名分支一样,是否会丢失对dev -branch的提交历史记录?如果是,我如何保留提交历史记录?

My question is like if I rename the branch, does commit history to the dev-branch will be lost or not? If yes, how do i keep my commit-history?

推荐答案

现在,我想将分支的名称从dev更改为development,我知道如何在GIT中重命名分支.我的问题是,如果我重命名分支,是否会将提交到dev分支的历史记录丢失或不丢失?如果是,我如何保留提交历史记录?

Now I want to change the name of the branch from dev to development, I know how to rename branch in GIT. My question is like if I rename the branch, does commit history to the dev-branch will be lost or not? If yes, how do i keep my commit-history?

您可以简单地从dev分支中创建一个新分支,然后删除dev分支.新分支将是您现有分支的副本,我经常这样做是为了防止在重新定级或合并时破坏分支.

You can simply create a new branch from your dev branch, and then delete the dev branch. The new branch will be a copy of your existing branch, I often do this to guard against breaking a branch when rebasing, or merging.

以下是示例输出:

# Normal state, for me at least
$ git branch
=> master
# Get into your dev branch.
$ git checkout dev
=> dev
# Now we make a new branch `development' based on `dev'
$ git checkout -b development
=> development
$ git branch -d dev

如果愿意,您可以始终在最后一步之前检查git log.但是Git中的所有分支只是特殊标记的引用.从dev创建development不会复制所有内容,因此保留它不会浪费任何空间.

You can always check the git log before the last step, if you prefer. But all branches in Git are just special tagged references. Creating development from dev doesn't duplicate everything, so you don't waste any space by keeping it.

这篇关于GIT重命名分支并保留所有提交历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆