1

git newbie here, used to subversion: I have some local changes that I've committed and now wanted to push but I got:

$ git push
Everything up-to-date

after a quick Google search, I found: git push says everything up-to-date even though I have local changes and I thought GREAT! and started following the recommendation in the accepted answer:

$ git log -1
#got the hash key
$ git checkout master
M       util/logging/cp_logging.cpp
Already on 'master'
Your branch is up-to-date with 'origin/master'.
#Now I got nervous and verified with git status 
#and git diff that my changes were still there
#just for safety I did a
$ git diff >save.patch
#followed by(as recommended):
$ git reset --hard 579823db25d2a821c2940608e9cb8122c2779b37
HEAD is now at 579823d Merge remote-tracking branch 'upstream/master'
#then I did a 
$ git status
# and realized that my changes were gone!

How do I get my changes (luckily saved save.patch) get back into my local working copy and then push the changes to the online repo from here? Should my changes not be committed in my local repo already (as I did a git commit earlier)?

1
  • 1
    git apply save.patch. Then git reset --hard is the git equivalent of a nuke so use with care when you have changes laying around your working tree. If it's committed stuff you are playing with, you can do all sorts of tricks to get it back from a hard reset but the same can not be said of stuff that hasn't been committed.
    – eftshift0
    Sep 27, 2018 at 2:57

1 Answer 1

1

That was my answer, 9 years ago, and only if your git status showed you you were not on any branch (detached HEAD)

Anyhow, you can use git apply to re-apply your saved patch.

Then add, commit, and push.

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.