[英]How to create a new branch without pre-merge remote-tracking commits in Git?
Whenever I create a new branch (git checkout -b <newBranchName>)
, I use to get many commit logs: 每当我创建一个新分支(git checkout -b <newBranchName>)
,我都会使用许多提交日志:
Merge remote-tracking branch 'upstream/master' into develop e53c044
Merge remote-tracking branch 'upstream/develop' into develop feda328
Merge remote-tracking branch 'upstream/develop' into develop 4bbd301
Merge remote-tracking branch 'upstream/develop' into develop 4dfcfcb
Merge remote-tracking branch 'upstream/develop' into develop bfaccfb
Merge remote-tracking branch 'upstream/develop' into develop 754c0ab
Merge remote-tracking branch 'upstream/develop' into develop b0454b0
Merge remote-tracking branch 'upstream/develop' into develop f96182f
How can I create a branch without such logs? 如何创建没有此类日志的分支?
Maybe orphan
parameter of git checkout
could help you: 也许git checkout
orphan
参数可以帮助您:
git checkout --orphan NEW_BRANCH
This will create a new branch named NEW_BRANCH with zero commits on it. 这将创建一个名为NEW_BRANCH的新分支,其上的提交为零。 But now all files stay in cache area, you could use "git rm --cached ..." to unstage: 但是现在所有文件都保留在缓存区域中,您可以使用“ git rm --cached ...”取消登台:
git rm -r --cached .
-r
here could unstage files recursively. -r
在这里可以递归取消暂存文件。
The commits for the new created branches are based on the parent branch you created from. 新创建的分支的提交基于您从其创建的父分支。
Such as if you create a new branch new
from develop
branch as below graph: 这样,如果你创建一个新的分支作为new
的develop
分支,如下图:
A---B---C developer
\
new
When you show the logs for new
branch, you will find the commits A
, B
and C
are showed. 当显示new
分支的日志时,您会发现显示了提交A
, B
和C
If you want to create the new
branch without showing the parent commits , you can create an orphan branch (execute on develop
branch): 如果要创建new
分支而不显示父提交 ,则可以创建一个孤立分支(在develop
分支上执行):
git checkout --orphan new
Then there will have no commits on new
branch. 这样就不会在new
分支上提交任何内容。 the commit history will as below: 提交历史如下:
A---B---C developer
new
If you want to create the new
branch with only part of the commits for it's parent branch develop
, you can use: 如果你想创建new
,只有在提交的部分分支为它的父分支develop
,你可以使用:
git checkout -b new <last commit you want to contain in new branch>
Such as if you want to contain only commits A
and B
in new
branch, you can use the command git checkout -b new <commit id for B>
, then the commit history will be: 例如,如果您只想在new
分支中包含提交A
和B
,则可以使用命令git checkout -b new <commit id for B>
,那么提交历史将为:
A---B---C developer
\
new
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.