0

Unintended I pull a remote branch feature1 into development

1. git checkout development
2. git pull origin feature1

The branch development is ahead of origin/development by N commits. I can't push changes to origin/development. After pull, I tried run merge --abort but it did not work.

Is there a way to undo all new changes (commits to push) in a branch in particular?

jjoselon
  • 2,641
  • 4
  • 23
  • 37

2 Answers2

3

Issue the following command while branch development is checked out:

git reset --hard origin/development

This will reset your local development branch to point to the same commit as origin/development (the commit you were on before pull).

Precautions: Do not use the --hard option if you have local uncommitted changes you wish to keep.

If you have unpushed commits on your local development branch you wish to keep you should use the commit id of the latest commit on development instead of origin/development.

David Sugar
  • 1,042
  • 6
  • 8
1

git reset should help you out. you can roll back commits on your branch.

Assuming the merge was clean and you just have a linear history, then executing this from the development branch:

git reset --hard HEAD~N

will undo the latest N commits on the development branch. Just be careful since the --hard will throw them away and they'll be gone forever if the commits aren't backed up on another branch. But it sounds like you already have those N commits on the feature branch.

doggie_breath
  • 782
  • 1
  • 6
  • 21
  • I've edited the question, still your answer works ? – jjoselon Jan 27 '20 at 15:33
  • Using the reflog would be easier than having to figure out what value of `N` to use. – chepner Jan 27 '20 at 15:34
  • @jjoselon if your development branch is N commits ahead of origin/development and none of those N commits should be on the development branch, then yes what I posted should work. Also see phd's comment above. – doggie_breath Jan 27 '20 at 15:36