I was trying to commit some changes to my secondary branch in my git repository. But when I committed, I lost all my changes. My repository is now like when I first cloned it (I cloned it from my prof's repository for an assignment) and lost all my work ! Is there a way to get back those changes? I can't use reflog because my last commit was a very long time ago. See the pictures pic1pic2
Asked
Active
Viewed 45 times
0
-
What about `git checkout -` to switch to last commit you did (`secondary` branch)? then push to remote branch by `git push origin secondary` – Sajib Khan Apr 02 '18 at 06:14
-
I hope this answer will help you (if you staged the files, otherwise it is lost :-() https://stackoverflow.com/a/11096537/717372 – Philippe Apr 02 '18 at 08:51
-
So I woke up this morning and somehow all my files were back. I took screenshots then they disappeared again wtf? At least now I can just retype everything. – Donat Apr 02 '18 at 15:18
1 Answers
0
Switch to your secondary
branch:
$ git checkout seconday # now current branch is 'seconday'
$ git log # see the commit history
Add
the untracked file, do Commit
, then Push
to remote seconday
:
$ git add -A # add the untracked files
$ git commit -m 'Message' # staged the changes
$ git push origin secondary # push to remote 'secondary'

Sajib Khan
- 22,878
- 9
- 63
- 73
-
I'm not sure how this helps ? Because in my secondary branch on github I still don't have the changes – Donat Apr 02 '18 at 15:11
-
So turns out that my changes were present in my secondary branch but I used that wrong "push" syntax so they didn't show on github. This answer helped ! Thank you – Donat Apr 02 '18 at 15:46
-