-2

Me and my friend were working on a branch. When my friend completed his work and push his work on the branch that we were working on.

Now I was about to pull the work done by him but instead of pulling from the branch that he was working on I mistakenly pulled from the master branch.

and there occurs a conflict. I know how to fix a conflict but I don't want to merge master into my working branch. therefore to rollback I used following commands

git reset .
git checkout -- .

this restored all the files back to the latest local commit. (I think so) But when I do git status it show some untracked files and also displays a message that says "All conflicts fixed but you are still merging."

Now I don't know what should I do to make sure that the whole project directory is restored to its original state before pulling the master branch.

kowsky
  • 7,265
  • 1
  • 23
  • 37
Amarjit Singh
  • 1,693
  • 11
  • 39
  • When you type `git status` what is the latest commit? When you pull something, you have to merge it with your local repo (which is done automatically), so if the last commit is the merge of your current local branch and the remote main branch, you would have to reset the head to the state before the merge, and then pull the changes from the correct branch. – wdc Nov 12 '18 at 08:10
  • https://stackoverflow.com/search?q=%5Bgit%5D+undo+merge – phd Nov 12 '18 at 11:11

1 Answers1

2

The right way would have been a git merge --abort; see this answer.

Since git says All conflicts fixed but you are still merging., i.e. the merge flag is still set, you can still use git merge --abort to reset to the state before the pull.

kowsky
  • 7,265
  • 1
  • 23
  • 37
  • `git merge --abort` fixed the message But there are still some untracked files. Do I have to delete them manually. – Amarjit Singh Nov 12 '18 at 08:45
  • Were there changes in the `master` branch that were not part of your shared feature branch when you accidentaly merged it? Do you know if the untracked files originate from `master` or from your branch? And are you sure you're on top of your original branch? – kowsky Nov 12 '18 at 08:50
  • Yes, I am sure that I am on top of my local branch (not remote). also the untracked files originate from master – Amarjit Singh Nov 12 '18 at 09:03
  • 1
    Then it should be safe to remove them, since you do not want to add them to your branch. They can be added if you ever merge with `master`. But you have to see for yourself if the files are needed in the current state of your branch or not. – kowsky Nov 12 '18 at 09:05