0

I wanted to make my branch up to date and mistakenly pulled from master branch using " git pull origin master " and now i have some 700 pending changes to commit. How do i undo this and not mess up anything in here?

Thanks!

skasar
  • 11
  • 4
  • 2
    Try `git merge --abort` – mousetail Jul 19 '22 at 14:40
  • 1
    Does this answer your question? [Abort a Git Merge](https://stackoverflow.com/questions/44048982/abort-a-git-merge) – evolutionxbox Jul 19 '22 at 14:40
  • my 2 cents, never use `git pull`, use `git fetch` and merge or rebase your job according to what you need – Ôrel Jul 19 '22 at 14:53
  • @Ôrel seems unnecessary, why? – AD7six Jul 19 '22 at 19:02
  • You don't know what will happen doing `git pull` , doing `git fetch` you can check what happens on the remote before updating your current branch. This is more robust and avoid surpise – Ôrel Jul 20 '22 at 13:08
  • @Ôrel what do you mean you don't know? – evolutionxbox Jul 20 '22 at 13:09
  • `git fetch` allows you to sync the remote state, and see the gap between your branch and the remote one. Doing `git pull` this will fetch and apply the modification – Ôrel Jul 20 '22 at 13:14
  • 1
    @Ôrel I suggest that's an unnecessary fear/restriction - there's no fundamental problem using `git pull` - but if your workflow works for you of course that's no problem. If you can be confident it's trivial to fix or establish previous state _if_ there is a problem after `git pull`(which would be exactly the same problem after rebasing/merging), there's no reason to shy away from using it. Just comes down to being familiar with a tool and using it appropriately :). – AD7six Jul 21 '22 at 10:48

3 Answers3

0

To undo the merge, you could use git reset --hard. This will reset the local repository to a previous state.

Be aware though that this will remove all uncommitted changes, potentially leading to a loss of work:

Alternatively, you can reset to a particular point in time, such as:

git reset --hard master@{"10 minutes ago"}
ethanknights
  • 154
  • 5
0

I used git stash and that took me back to the clean working directory. Thank you for all your responses!

skasar
  • 11
  • 4
  • 1
    Be careful stashing during a merge. [You may have trouble applying it again](https://stackoverflow.com/questions/9009354/git-stash-during-a-merge-conflict). Also I don't think stashing aborts the merge – evolutionxbox Jul 19 '22 at 15:59
0
git reset --hard master@{"[time]"}

and be sure to replace time since the last pull for detailed answer check this

Undo git pull, how to bring repos to old state