Committing after checkout. Git says "You are not working on a branch."
I reverted to a previous commit and made some changes.
Now I want to commit my chang开发者_如何学运维es and GIT says "You are not working on a branch. This commit will be unreferenced when switching to another branch and can be lost."
I don't care about any commits I made after this one, how do I commit now?
How did you revert? What is the result of git status?
It looks like you've reset to a commit on a non-local branch. You can create a new branch for your commits using;
git checkout -b new_branch_name
You may need to delete or force-push the old branch, but only do so if you are sure you do not need the commits on it. I find using git log or gitk can help to visualise this.
It sounds like you created a detached head by using git checkout
to turn back the clock. This means your current HEAD
does not point to the head of a branch anymore.
If you're 100% sure you don't want anything after the commit, you can use git stash
to save your current work, git reset --hard <commit>
(man page) to revert back to the commit, then git stash apply
to apply your new changes.
精彩评论