I think this is the stupid thing a developer can do, but I did it accidentally.
I had made changes to local master and did not commit it. And suddenly I made git pull
, and then the local master got updated with my changes and remote repo changes. Now I can merge the changes by resolving conflicts if any. But I want to undo this pull and preserve the changes I have done which are not committed. Is this possible? Correct me if I am wrong. Please help me.
Asked
Active
Viewed 1,781 times
4

Anil
- 1,748
- 8
- 32
- 67
-
I'm not sure what you're asking. The git pull completed and now you have both new code and your uncommitted changes and you want to go back to just having your uncommitted changes? – chevybow Oct 05 '18 at 16:28
-
@chevybow, yes bro – Anil Oct 05 '18 at 16:30
-
Read this one: https://stackoverflow.com/questions/34519665/how-to-move-head-back-to-a-previous-location-detached-head/34519716#34519716 – CodeWizard Oct 05 '18 at 16:54
-
https://happygitwithr.com/pull-tricky.html, this section of the git doc has several common scenarios, and 28.1.3 git stash with conflicts, addresses exactly your situation. Basically you either follow the steps and resolve conflicts, or git reset to undo pull *without losing local changes". – BJYC Mar 03 '21 at 01:24
1 Answers
2
stash your changes, take back your local branch with a reset --hard and then unstash
git stash save "saving my uncommitted changes so I don't lose them when I reset"
git reset --hard revision-where-branch-was-before-pulling # check git log or git reflog to see the ID you want
git stash pop # get my changes back on my working tree
That should do

eftshift0
- 26,375
- 3
- 36
- 60