7

GitHub seems to be a bit lost after a couple of operations - and I certainly am...

So, here is the story:
I am new to git, and new to github. In my repository I had a branch (let's call it B) where I was working on a feature.

  1. To make things transparent I created a pull request.
  2. My collaborator (complete git/github newbie) clicked to merge the pull request (probably just exploring the interface).
  3. The feature was not ready so I reverted the merge.

Now I would like to continue my work on the branch B and later merge it, but although the branch is is different by more than 800 lines GitHub shows that there is only one line of difference (one commit).

This may be because I was trying to reopen the old pull request after reverting the changes. I did reopen the pull request but the option to merge was no longer available. I tried closing or opening the old pull request and creating a new pull request (pulling branch B to master) but this shows only one commit as if all the rest was eaten up by the original pull request (although reverted). But if I try to pull master to B - it shows all the differences (about +800/-300 difference).

I would like to be back to work peacefully on branch B - I would like to be back to the moment when B could be automatically merged (now it is not possible becasue new pull requests show only one minor difference between B and master while the actual difference is different). What is the easiest way to do so?

mmagnuski
  • 1,249
  • 1
  • 11
  • 23

3 Answers3

6

Instead of trying to fiddle with B, you could simply:

  • create a new branch C,
  • starting with a previous commit from B (where the merge was easy)
  • cherry-pick any commit from B you need back in C

You can then make a PR from C if you want.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I understand this is possible, but my knowledge of git is VERY basic - push, add, commit , checkout mostly. Therefore I do not know how to start from some previous commit or cherry-pick. Could you direct me to relevant resources? Sorry for my basic knowledge - if I knew more I would not have had this question I guess :) – mmagnuski Aug 25 '14 at 11:52
  • @Impon_de_Rable then http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging#Basic-Branching is a good start – VonC Aug 25 '14 at 11:53
  • I planned to read the book, but I prefer to resolve this issue now and be able to work on the code today/tomorrow rather than wait till I read the book. – mmagnuski Aug 25 '14 at 11:57
  • @Impon_de_Rable I understand: all I meant was to illustrate the way to quickly create a branch from any commit you want from B history. `git checkout -b C `, in order to reset the work in a new branch from a more stable point in time. – VonC Aug 25 '14 at 11:59
  • Ok, thanks, I will try this and then read on cherry-pick then. I will accept your answer soon :) – mmagnuski Aug 25 '14 at 12:03
  • @Impon_de_Rable it would be best to test first, then accept (it it works) ;) – VonC Aug 25 '14 at 12:04
  • That's exactly what I mean. – mmagnuski Aug 25 '14 at 12:05
  • @Impon_de_Rable great! I have written a bit more a PR: http://stackoverflow.com/a/14681796/6309 – VonC Aug 25 '14 at 16:43
2

I think the cleanest solution is to create a new branch off master and then revert the commit that reverted your PR. Something like:

git checkout master
git checkout -b retry_B  # create new branch
git log  # find commit hash for the revert
git revert <hash_from_revert>
esk
  • 166
  • 1
  • 4
1

I know this is an old question, but I just had the same problem and found an easy get-around:

I just created a new branch from master and replaced the contents of the project folder with the ones I had in the branch I was working on before. (Literally copied and pasted the folder contents). After this, when I ran git status, it showed the correct modifications.

It's a more primitive solution but it works, and after that I was able to create the PR which showed the correct changes from master and the branch I was working on.

martezan
  • 31
  • 4