简体   繁体   English

GIT:分支分离HEAD后不会丢失更改

[英]GIT: Not lossing changes after branch detached HEAD

I have been working in git submodule and I was ready to push my changes when I got this message: 我一直在git子模块中工作,当收到以下消息时,我准备推送更改:

$ git push
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>

I ran the following command thinking this may fixed: 我运行以下命令认为可以解决此问题:

git checkout master

But I got this message: 但是我得到了这个信息:

Warning: you are leaving 1 commit behind, not connected to
any of your branches:

  2f1b645 my changes

If you want to keep it by creating a new branch, this may be a good time
to do so with:

 git branch <new-branch-name> 2f1b645

Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

My question to you guys is how can push my changes to master? 我对你们的问题是如何将我的更改推向高手?

Just cherry-pick that commit on your master branch: 只是挑选您的主分支上的提交:

git cherry-pick 2f1b645

The problem you had was that you were not on a local branch when you committed that changes. 您遇到的问题是,提交更改后您不在本地分支上。

By the way, you could also have rebased or merged your commit. 顺便说一句,您还可以重新设置基础或合并提交。

git rebase 2f1b645

or 要么

git merge 2f1b645

Probably to rebase it would have been the nicest solution, but since I'm not 100 percent sure what you had checked out, the cherry pick is the safest way to go. 可能需要重新设置基准,这将是最好的解决方案,但是由于我不确定100%确认了什么,因此选择樱桃是最安全的方法。

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

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