Git:“目前不在任何分支上”。有一种简单的方法可以在保持更改的同时回到分支上吗? [英] Git: "Not currently on any branch." Is there an easy way to get back on a branch, while keeping the changes?
问题描述
因此,我在存储库中做了一些工作,当我即将提交时,我意识到我目前不在任何分支上。
发生这种情况在使用子模块的时候很多,而且我可以解决这个问题,但是这个过程很乏味,我一直在想,必须有一个更简单的方法来做到这一点。
有没有一种简单的方法可以在保留更改的情况下恢复分支?
git存储
git checkout某些分支
git stash pop
如果您已经提交并且没有改变任何内容:
git log --oneline -n1#这会给你SHA
git checkout some-branch
git merge $ {如果你已经提交并完成了额外的工作:
b
git stash
git log --oneline -n1#这会给你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屋!