git 合并(无分支)到 master

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4675726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:56:14  来源:igfitidea点击:

Merge (no branch) into master

gitversion-control

提问by Keyo

dave@dave-dev:/media/dev/belgravia$ git branch
* (no branch)
  master

I'm not sure how this happened, but is there a way I can merge no-branch into the master. I'm not sure how I can merge two branches when one of them is not a branch. The commits in no-branch seem to be loose. I'm afraid that checkout masterwill cause data loss.

我不确定这是怎么发生的,但是有没有办法将 no-branch 合并到 master 中。当其中一个不是分支时,我不确定如何合并两个分支。无分支中的提交似乎很松散。恐怕这checkout master会导致数据丢失。

回答by Greg Hewgill

Use git showto get the SHA1 commit ID of the current HEAD. With that information, you can't lose those commits.

使用git show得到SHA1提交当前HEAD的ID。有了这些信息,您就不会丢失这些提交。

Then, switch to master and:

然后,切换到 master 并:

git merge abc123

where abc123is the SHA1 from the first step.

abc123第一步的 SHA1在哪里。

回答by Justin_lu

Maybe you can commit it on current branch(no-branch)

也许你可以在当前分支上提交它(无分支)

Then you have to do:

然后你必须这样做:

git reflog

After that you can get the id of this commit like 1d84d08

之后,您可以像 1d84d08 这样获得此提交的 ID

do:

做:

git checkout master 
git merge 1d84d08

回答by venkat

The reason you have (no branch) is you have done:

你有(没有分支)的原因是你已经完成了:

git checkout REMOTE_BRANCH_NAME
  • In order for you to work locally on that branch you have to do: git checkout -b local_branch_new_name
  • now do a: git branch - a
  • you will see:
  • 为了让您在该分支上本地工作,您必须执行以下操作: git checkout -b local_branch_new_name
  • 现在做一个: git branch - a
  • 你会看见:

local_branch_new_name

  master

local_branch_new_name

  master
  • From here you can merge a branch into master the usual way. switch to master and do:

    git merge local_branch_new_name

  • 从这里您可以按照通常的方式将分支合并到 master 中。切换到 master 并执行以下操作:

    git合并local_branch_new_name