Git:“目前不在任何分支上”。有一种简单的方法可以在保持更改的同时回到分支上吗? [英] Git: "Not currently on any branch." Is there an easy way to get back on a branch, while keeping the changes?

查看:1259
本文介绍了Git:“目前不在任何分支上”。有一种简单的方法可以在保持更改的同时回到分支上吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在存储库中做了一些工作,当我即将提交时,我意识到我目前不在任何分支上。



发生这种情况在使用子模块的时候很多,而且我可以解决这个问题,但是这个过程很乏味,我一直在想,必须有一个更简单的方法来做到这一点。



有没有一种简单的方法可以在保留更改的情况下恢复分支?

解决方案

如果您还没有提交:

  git存储
git checkout某些分支
git stash pop

如果您已经提交并且没有改变任何内容:

  git log --oneline -n​​1#这会给你SHA 
git checkout some-branch
git merge $ {如果你已经提交并完成了额外的工作:





b

  git stash 
git log --oneline -n​​1#这会给你SHA
git checkout some-branch
git merge $ {commit-sha}
git stash pop


So I've done some work in the repository and when I'm about to commit I realize that I'm not currently on any branch.

This happens a lot when working with submodules and I am able to solve it, but the process is tedious and I've been thinking that there must be an easier way to do this.

Is there an easy way to get back on a branch, while keeping the changes?

解决方案

If you have not committed:

git stash
git checkout some-branch
git stash pop

If you have committed and have not changed anything since:

git log --oneline -n1 # this will give you the SHA
git checkout some-branch
git merge ${commit-sha}

If you have committed and then done extra work:

git stash
git log --oneline -n1 # this will give you the SHA
git checkout some-branch
git merge ${commit-sha}
git stash pop

这篇关于Git:“目前不在任何分支上”。有一种简单的方法可以在保持更改的同时回到分支上吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆