I did a git commit -am
followed immediately by git stash
and got the messageNo local changes to save
When I run git status
I getYour branch is ahead of 'origin/master' by 3 commits.
Is this right?
I was working on some stuff and made some commits but haven't pushed the changes. Now I want to 'stash' them and go back to a clean version (my latest pushed
changes - don't know how to refer to this)
How do I stash my work that I haven't pushed yet and revert to the latest pushed master branch?
This message from git means that you have made three commits in your local repo, and have not published them to the master repository. The command to run for that is git push {local branch name} {remote branch name} .
The message you are seeing (your branch is ahead by one commit) means your native repository has one commit that hasn't been pushed yet. In other words: add and commit are local operations, push, pull and fetch are operations that interact with a remote.
It means that you have some commits in your branch that weren't pushed to origin. To keep your local branch in sync with origin, you need to push your code to that frequently.
If I understand if right, you need:
1) Save your local changes.
git add -A
git stash
2) Backup your commits
git branch my_master_backup
3) Reset your HEAD back to origin/master
git reset --hard origin/master
4) Do some work that you want to to with the "clean version"
5) Restore changes that you have made with your commits. Fix conflicts if any.
git merge my_master_backup
6) Drop the backup branch. If you can't delete it means that you haven't fully merged your backup branch and the master.
git branch -d my_master_backup
6) Restore your local changes from the step 1:
git stash pop
PS: you can avoid creating a backup branch and use reflog. When you want to restore your commits you need to execute git merge HEAD@{X}
where X is the number of the desired commit from reflog.
Thanks for the help everyone. What I did wasgit reset --soft origin/master
git stash save 'stashing my unfinished changes'
This undid all my commits but left all my changed files. I was then able to stash the changes since they weren't committed yet. It automatically reset my local files to origin/master after I stashed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With