What to do after soft reset to my last commit ? Commit or pull first? or Pull then commit, or…?


I needed to discard a file of my last commit, so I soft reset it and now I can commit again but GitHub Desktop gives me the Pull origin option and I am wondering what to do:

  • Commit and then push or vice versa?
  • Or pull force or something?

I make soft reset of my last commit and discard a file so now I have a pull origin option in the Git Hub desktop.


What a soft reset is

A soft reset undoes the most recent commit but leaves both your working tree and the index in a state that still reflects that undone commit. Thus:

  • If you were to commit right after the soft reset without changing anything else, you would get a commit that looks exactly like the commit you just undid (except maybe for the message, and of course the time).

  • If, on the other hand, you make a change in the working tree and add that change to the index and then commit, you have replaced the undone commit with a new and different commit.

(Note that you could have accomplished exactly the same thing with commit --amend.)


So then what?

  • If you had already pushed the "last commit" before you reset and made a new commit, you now have changed history. Therefore, if the purpose is (say) to make sure that this new commit lacks the "naughty" file on both your local and remotely, you must push with force in order to get the new commit to upload to the remote.

  • On the other hand, if you have not pushed the "last commit" before the reset, then there is nothing particular to do; after doing a new add-and-commit you can just push directly to the remote if that’s your goal, or you can just keep working (edit-add-commit).

Answered By – matt

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published