-2

[SOLVED]

I have an unmerged branch in my main repository, not the local one, it has 4 commits by another developer, all the codes were messed up, how can I drop all these 4 commits?

Thanks to @SLaks for your pointer, I just did git pull, then git reverts for those 4 commits, then pushed the changes to my main repository, exactly what I wanted.

Budianto IP
  • 1,118
  • 1
  • 13
  • 27
  • Look at this http://stackoverflow.com/questions/1146973/how-do-i-revert-all-local-changes-in-git-managed-project-to-previous-state – Mhd Feb 22 '17 at 21:28
  • Hi, thank you, but I have edited my question, the problem is these 4 commits are not in my local repo, but in the main repo :) – Budianto IP Feb 22 '17 at 21:29
  • 1
    Then you can pull the branch to your local repo. – SLaks Feb 22 '17 at 21:30
  • Thank you @SLaks, I know what to do from this point – Budianto IP Feb 22 '17 at 21:39
  • @budiantoip don't put the solution in the question, post it as an answer instead. – 1615903 Feb 23 '17 at 07:42
  • Some people don't like that way, I mean asking and then answering by the same person, it's as if intentionally doing it for collecting points, that's why I put the solution in the question – Budianto IP Feb 23 '17 at 20:04
  • @budiantoip that is wrong, see https://stackoverflow.blog/2011/07/01/its-ok-to-ask-and-answer-your-own-questions/ – 1615903 Mar 06 '17 at 09:24

3 Answers3

0

You can do something like this:

git revert <commit>

For more look here.

Also look at this post.

Community
  • 1
  • 1
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
  • Hi sorry, I think I wasn't clear enough, the problem is the branch is located in the main repo, not the local one, how can I drop all the changes? – Budianto IP Feb 22 '17 at 21:28
  • @budiantoip look at this post: http://stackoverflow.com/questions/4114095/how-to-revert-git-repository-to-a-previous-commit – Pritam Banerjee Feb 22 '17 at 21:30
0

Just remove the whole branch both locally and remotely. If you don't want to remove it whole, you might have to revert all 4 commits.

Local

git branch -d local branch

Remote

git push origin --delete remote_branch

silidragos
  • 161
  • 8
0

I think your bet is git reset HEAD --hard Look at this question: How to move HEAD back to a previous location? (Detached head)

Community
  • 1
  • 1
Mhd
  • 2,778
  • 5
  • 22
  • 59