-2

I have a project with a submodule:X,and run

git submodule update --init --recursive

to fetch X, then made a bunch of changes on X and committed them with comment "changes YYYY", then try to push changes to master, but got something like "not in any branch"(not exact description), so I tried

git checkout origin master

Right now, X is in branch master, but git log doesn't show "changes YYYY". How can I get "changes YYYY" back?

3

1 Answer 1

0

This solves my problem:

git fsck --no-reflogs | find  "dangling commit"
1
  • 1
    If it is a repo you have been using for a long time, you may have lots and lots of dangling commits. To locate a commit which was recently checked out (before you checked out master branch), it is probably easier to use: git reflog -10. This would show the 10 latest commits which were checked out in the current worktree. From there, you could locate the commit you were looking for and git cherry-pick <commit-hash> it to the current branch.
    – Alderath
    Commented Aug 8, 2022 at 11:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.