-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?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Alex Luya
  • 9,412
  • 15
  • 59
  • 91
  • Does this answer your question? [Git: "Not currently on any branch." Is there an easy way to get back on a branch, while keeping the changes?](https://stackoverflow.com/questions/4735556/git-not-currently-on-any-branch-is-there-an-easy-way-to-get-back-on-a-branch) – Piglet Aug 08 '22 at 10:08
  • https://superuser.com/questions/116153/rescuing-files-and-commits-from-no-branch-in-git – Piglet Aug 08 '22 at 10:10
  • @Piglet Thanks.I have checked out the master,questions is how to get changes back,not how to put the changes to the master – Alex Luya Aug 08 '22 at 10:32

1 Answers1

0

This solves my problem:

git fsck --no-reflogs | find  "dangling commit"
Alex Luya
  • 9,412
  • 15
  • 59
  • 91
  • 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 ` it to the current branch. – Alderath Aug 08 '22 at 11:00