2

I have merged development branch into my wpf-design-guidelines branch and something went wrong. So I reverted to the commit before the merge with reset --hard commit_SHA, that is the point with the comment: Query Stylecop corrections (see image below).

But now I have to pull before I can push new things as I am 24 commits behind. I would like to know how can I set this commit (Query Stylecop corrections) as the Head of the branch, what are the best options here ? I want to continue my work from here as if the merge never happened.

ps. I am the only one working on the branch wpf-design-guidelines. I saw this post here and did what it said in Hard delete unpublished commits.

git problem

Community
  • 1
  • 1
Devid
  • 1,823
  • 4
  • 29
  • 48

1 Answers1

2

So you want to reset the origin (remote, not on your machine) branch to your local branch? Do this:

git push origin wpf-design-guidelines --force

EDIT: As amalloy pointed out and as you may imagine (--force), this is kind of dangerous. Check out this link for more information: https://developer.atlassian.com/blog/2015/04/force-with-lease/

Johannes Filter
  • 1,863
  • 3
  • 20
  • 25
  • 1
    Not enough warning symbols. This is a dangerous and destructive operation to do when you don't know what it does. It is often fine, but don't recommend it without explaining the pitfalls. – amalloy Apr 25 '17 at 16:17
  • 1
    This is the answer to your question. This will set the remote branch to what it is on local and "forget" about the revisions that are not part of it. This answer assumes that the remote branch and the local branch have the same name. That is not mandatory so you could say: ```git push --force HEAD:``` to put where you are right now as the branch on the remote (doesn't care where you are, doesn't even have to be related to the branch as it is on the remote). Powerful stuff so it has to be used with care so you don't mess things up. – eftshift0 Apr 25 '17 at 16:24
  • Oh, and by the way, it's not like you should be _afraid_ of push --force, i exists for a reason. If you are aware of what you are doing, it's ok to use it. If you are not quite sure of what you are doing, you can still use it. It will tell you the revision ID that the remote branch was pointing to before the push so you can get it back to how it was before, just in case. – eftshift0 Apr 25 '17 at 16:33
  • @Edmundo thanks for the information. I am a bit concerned about the development branch because I don't want to change there anything. But I will try this solution. – Devid Apr 25 '17 at 19:44
  • 1
    I changed the answer to include your specific branch. It will not touch the development branch. ;) – Johannes Filter Apr 25 '17 at 19:56
  • @JohannesFilter it worked. Git is easy to start working with, but going deeper down starts to get really complicated. – Devid Apr 26 '17 at 11:13
  • I think a lot of people (including myself) can relate to that.✌️ – Johannes Filter Apr 26 '17 at 12:54