简体   繁体   English

GIT重命名分支并保留所有提交历史记录

[英]GIT Renaming a branch and keeping all commit history

I have a question regarding renaming a branch in git. 我有一个关于在git中重命名分支的问题。 I created a local branch dev and pushed branch to remote. 我创建了一个本地分支dev并将分支推送到远程。 I did lots of work on the dev branch and am updating remote branch regularly. 我在dev分支上做了很多工作,并定期更新远程分支。

Now I want to change the name of the branch from dev to development . 现在我想将分支的名称从dev更改为development I know how to rename a branch in GIT. 我知道如何在GIT中重命名分支。

My question is like if I rename the branch, does commit history to the dev -branch will be lost or not? 我的问题是,如果我重命名分支,确实将dev -branch的历史记录丢失或不丢失? If yes, how do i keep my commit-history? 如果是,我如何保留我的提交历史记录?

Now I want to change the name of the branch from dev to development, I know how to rename branch in GIT. 现在我想将分支的名称从dev更改为开发,我知道如何在GIT中重命名分支。 My question is like if I rename the branch, does commit history to the dev-branch will be lost or not? 我的问题是,如果我重命名分支,是否会丢失或不丢弃dev-branch的历史记录? If yes, how do i keep my commit-history? 如果是,我如何保留我的提交历史记录?

You can simply create a new branch from your dev branch, and then delete the dev branch. 您只需从dev分支创建一个新分支,然后删除dev分支。 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. 新分支将是您现有分支的副本,我经常这样做是为了防止在重新定位或合并时破坏分支。

Here's a sample output: 这是一个示例输出:

# 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

You can always check the git log before the last step, if you prefer. 如果您愿意,可以随时检查最后一步之前的git log But all branches in Git are just special tagged references. 但是Git中的所有分支都只是特殊的标记引用。 Creating development from dev doesn't duplicate everything, so you don't waste any space by keeping it. dev创建development并不会复制所有内容,因此您不必通过保留它来浪费任何空间。

根据手册页git branch -move - 移动/重命名分支相应的reflog。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM