简体   繁体   English

如何通过没有更改的提交创建新的远程分支?

[英]How can I create a new remote branch by a commit with no changes?

When I create a new branch and push it to my git repo, the new branch is lined up with master branch because I did not make any changes.当我创建一个新分支并将其推送到我的 git 存储库时,新分支与 master 分支对齐,因为我没有进行任何更改。 This is how I did it.我就是这样做的。

git checkout -b newbranch
git push -u origin newbranch

I want to create a branch with a commit so that others can see a commit message that a branch was created.我想创建一个带有提交的分支,以便其他人可以看到创建分支的提交消息。 But, I do not want to make any changes in this commit.但是,我不想在此提交中进行任何更改。 Basically, my new branch should be ahead of master by 1 but files are identical with those in master.基本上,我的新分支应该在 master 之前 1,但文件与 master 中的相同。

How can I do this?我怎样才能做到这一点? I tried git commit -m "created branch newbranch" before the git push , but git told me that there is nothing to commit.我在git push之前尝试git commit -m "created branch newbranch" ,但 git 告诉我没有什么可以提交的。

I guess --allow-empty is what you are looking for.我猜--allow-empty是你要找的。 Also see here也见这里

git checkout -b new-branch-name
git commit --allow-empty -m "message"
git push <remote> HEAD:branch-name

If I understood you correctly what you want to achieve is unfortunately impossible.如果我正确理解了您,那么不幸的是,您想要实现的目标是不可能的。 When you create a branch you essentially create a commit that reference to other commit.当您创建一个分支时,您实际上创建了一个引用其他提交的提交。 If you don't want to change anything in branch please add a file and commit and then remove that file in next commit.如果您不想更改分支中的任何内容,请添加一个文件并提交,然后在下一次提交中删除该文件。

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

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