2

Pulling my hair out here as I cannot seem to get this to work out.

I am aware that this is a duplicate of other questions that have been asked and answered however I am not sure if I am missing something here.

I was trying to push a commit to my repo, there was a large file and it came up with an error about it being over 100mb. So i removed the file and tried to commit again however it seemed that it still had the file in the committed changes so it failed again.

I then thought that running git reset --hard origin/master would clear the commits but it clears the changes that have been made. I've lost like a months work now and I am really not feeling great.

On the other questions, it suggests using git reset HEAD@{1} to revert the previous reset. I did this however when the reset completes, i do not have my files back, i did git status and it shows like

    deleted:    view/portal/reports/frequent-calls.view.php
    deleted:    view/portal/reports/not-contacts.view.php
    modified:   view/portal/reports/reports.view.php
    modified:   view/portal/reports/results.view.php

There the files marked as deleted are the ones that I want back. I am not sure if I am supposed to do something else now after this to get the files back. I would really appreciate any advice here!

4
  • git reset --hard is not capable of losing committed changes. Is this really "a months [worth of]" uncommitted changes? Aug 2, 2015 at 23:25
  • @user2864740 Does that mean that my data is there somewhere? After the initial reset my new files just disappeared from the working directories. I promise you, it's a whole month of changes, that was just an example of what is going on in git status. I have no idea how to get my files back and this is one of the lowest points in my career, I am supposed to demo this in the morning :/ Aug 2, 2015 at 23:28
  • 1
    All the changes that were ever successfully committed, yes. (Staged files are still uncommitted.) The first step is to find out where/if the changes actually live. Start with looking at git log (the --graph option may also be useful). Aug 2, 2015 at 23:33
  • @user2864740 I see this in the log: commit d8094df3c6a9bc663eaa49fc6946b24758cc765e Author: rem <rem> Date: Mon Aug 3 00:10:53 2015 +0200 Management & Customer Portal Updates was this a successful commit? Aug 2, 2015 at 23:37

1 Answer 1

8

You pointed your repo to origin/master. To come back you have to do the same.

Your script is not working because you have to add the --hard option too.

git reset --hard HEAD@{1}

However. If you are been doing more things since your first reset. It may not work now.

You should find your last commit with reflog command.

git reflog

You will see the latest positions of HEAD. Look for the previous one to the problematic reset. You can use the SHA1 or the position in the list.

git reset --hard SHA1

Or

git reset --hard HEAD@{theNumber}
3
  • I have not got the words to express how much that has helped. Thank you so much, really and truly! Not only have you provided perfect clarity on this matter, you've helped me out big time. I am so tired I can barely keep my eyes open, i wouldn't have figured this out and I would have gotten fired :/ God bless you and your family too! Aug 2, 2015 at 23:49
  • Remember, if you commited, it is there for good. git never erases. You are welcome.
    – blashser
    Aug 2, 2015 at 23:55
  • That is the thing though, my initial commit failed as I had my sql dump within there that was over 100mb. Given that, I was unsure of whether these changes would have been tracked as the commit was not actually successful, well in my mind anyways. Hence my hernia about losing my data. After playing with reflog, it seems that it always tracks the changes while using reset, what I was missing is the fact that --hard forces an overwrite while disregarding any unstaged changes. In this instance, it is the only thing that will work. Awesome, thanks again! Aug 3, 2015 at 0:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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