Search code examples
gitgit-pull

Undo Git Pull without losing untracked files?


I have a feature branch called testing_automation that I haven't committed in over a week. I have a lot of new, untracked files in the branch. I went to go to develop branch to check a different task but messed it up.
I will list what I did in order:

(Current Branch 'feature/testing_automation'):

  1. git stash
  2. git checkout . (undo any locally compiled npm files)
  3. meant to run git checkout develop but ran git pull develop

Now I have conflicts since it pulled develop in but I also don't want fix them because when I go to run git stash apply , there will be conflicts again. How can I undo the git pull develop from my feature branch without losing the untracked files. I have all the tracked files in git stash so I am not worried about losing those -- I can just apply those.


Solution

  • First I advise you to backup your entire project directory before doing anything.

    git merge --abort should stop the pull's merge conflict resolution and bring things to how they were.

    (Remember that a pull is simply git fetch followed by git merge - That's the reason we --abort a merge and not a pull. The merge part is the part that caused those conflicts)