I have a file that I should have committed but forgot all about. I went on to make more changes to a file. What I want to do is revert to where I should have committed, do a commit at that point, but still then get my new changes back. How do I do this in the most economical way?
Thanks.
EDIT: Just to explain the flow a bit.
- I have file.php which has been committed and is in a working state.
- I make changes to file.php which is the new production copy of file.php. This file is not committed, but should be.
- I make more changes to file.php and remember that I wanted to commit file.php.
What I want to do now is save my recent changes (so git stash may come in handy here, thanks for that!) go back to the second bullet point, commit, then continue on. Is there a way to get to that middle uncommitted point?
FURTHER EDIT:
I think the bit I’m not explaining well, is that there is no commit down for the second point above. In that state it doesn’t belong to the previous commit, but a new commit that doesn’t yet exist.
If by “forgot to commit” you mean forgot to “push”, then… there is hope 🙂
If you have commited your previous changes to the local git repo you can use git stash, to save the new changes in a “stash” and revert them. (you can use the same command to recover the changes from the stash.. see the link)