0

This is exactly what I did:

I did a lot of work on branch new-feature.

I added and committed it

git add .
git commit -m "did lots of work"

I checked out main

git checkout main

I merged new-feature into main

git merge --no-ff new-feature

I checked out a new branch.

git checkout -b new-branch 

did lots of work there, added, committed it, checkout out main and merged it in, just as before.

Then I checked out new-feature and all my work I committed back then is gone!!

I don't know what happened. It was definitely all there when I committed it originally. Where did it go? It's almost like the last commit I made - the most important one - on that branch, it gone!

Any advice?? (freaking out a bit here)

CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
  • git does not forget commits. Either there never were commits, or they have been removed, accidentally maybe, or you are simply working on another clone of the repository now which has not get received the commits in question. I often miss that some command like a commit fails. Happens. Then there simply is no commit. – arkascha Mar 22 '15 at 18:10
  • I definitely made the commits. I noticed now, that my command prompt was in a subfolder of my main projects when I made the commits.. could that be the issue? – CodyBugstein Mar 22 '15 at 18:17
  • Is there any way I can get my work back :-( ? – CodyBugstein Mar 22 '15 at 18:17
  • Making a commit in a subfolder is perfectly fine. – arkascha Mar 22 '15 at 18:20
  • If you can "get back your work" is something I really cannot answer, sorry. I know nothing about your repository, what you did (or think you did), what really happened. I cannot say anything about all that. Sorry. – arkascha Mar 22 '15 at 18:21
  • One idea: Could it be that you actually did _not_ checkout that old branch "new-feature", but a new one? Remember: those are just names, maybe the old or the new one is spelled slightly different? List your branches and check. – arkascha Mar 22 '15 at 18:22
  • @arkascha I wish. But it's definitely that branch. I have Atlassian SourceTree open to verify – CodyBugstein Mar 22 '15 at 18:23
  • @arkascha I'm totally screwed :-( :-( :-( – CodyBugstein Mar 22 '15 at 18:24
  • Ah, so you have a remote clone of the repository? But you did not push the commits there? Why not? But anyways: as said: _git does not simply forget commits_. Either there never were commits or they were removed or you are looking at the wrong place. Sorry that I can't be of more help. – arkascha Mar 22 '15 at 18:30
  • Sometimes it helps to look through the bash history step by step to see what has _really_ been done. That sometimes delivers big surprises... – arkascha Mar 22 '15 at 18:32
  • @arkascha I did. I have my command prompt window open and I can see everything I did for the past few days. It's weird.. it seems when I made the commits to my work, those files didn't show up with an `M` next to them. They don't appear. – CodyBugstein Mar 22 '15 at 18:37
  • Aha. So you did not actually create a commit with these changes (whyever). That explains why there is no commit now. SO the question is: 1. where were the modifications and 2. are they still there somewhere? Maybe you stashed? Maybe those were new files you did not add? And: you say you did the commit in a subdirectory. That is fine, _but_: it won't consider files outside that subfolder. But that would _not_ explain why the changes are gone. They would just not get submitted and either be left or prevent a switch of branches because of a collision which git would tell you. – arkascha Mar 22 '15 at 18:38
  • @arkascha then that is the issue. I made the commits while in `A/B/C` but the files I changed were in `A/P/Z` – CodyBugstein Mar 22 '15 at 18:40
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/73535/discussion-between-arkascha-and-imray). – arkascha Mar 22 '15 at 18:41
  • 1
    if you did the `git commit -m "did lots of work"` correctly and it wasn't too long time ago, you should be able to find it by `git reflog`, search for the "did lots of work" – Mykola Gurov Mar 22 '15 at 19:59
  • @MykolaGurov git reflog worked for me. thank you. – abhijith v Oct 06 '22 at 12:44

1 Answers1

0

Turns out my mistake was that I was navigated to a subfolder of my base folder when I made the commits and the changes I wanted to commit were in a different subfolder.

CodyBugstein
  • 21,984
  • 61
  • 207
  • 363