www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Confused about github rebasing

reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
I'm trying to submit a pull request for druntime, but I'm running into a
git problem. This is what I did:

- (I forgot that my master branch is out of date)
- created a new branch for the fix and committed some changes
- switched to master and ran 'git pull'
- now master is ahead of the branch by a number of commits
- switched back to branch
- ran 'git rebase master' to pull in changes from master and apply my
  changes on top of it
- checked that history looks clean
- 'git push -u origin newbranch'
- submit pull request: but now github thinks my branch has a whole bunch
  of commits I didn't make (looks like the commits made by rebase).

So my question is, what did I do wrong, and what's the right way to
pull in the latest changes from upstream without messing up the history?


T

-- 
English is useful because it is a mess. Since English is a mess, it maps
well onto the problem space, which is also a mess, which we call
reality. Similarly, Perl was designed to be a mess, though in the
nicests of all possible ways. -- Larry Wall
Mar 15 2012
parent reply =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= <xtzgzorex gmail.com> writes:
On 15-03-2012 20:13, H. S. Teoh wrote:
 I'm trying to submit a pull request for druntime, but I'm running into a
 git problem. This is what I did:

 - (I forgot that my master branch is out of date)
 - created a new branch for the fix and committed some changes
 - switched to master and ran 'git pull'
 - now master is ahead of the branch by a number of commits
 - switched back to branch
 - ran 'git rebase master' to pull in changes from master and apply my
    changes on top of it
 - checked that history looks clean
 - 'git push -u origin newbranch'
 - submit pull request: but now github thinks my branch has a whole bunch
    of commits I didn't make (looks like the commits made by rebase).

 So my question is, what did I do wrong, and what's the right way to
 pull in the latest changes from upstream without messing up the history?


 T

Let's say you're on your branch with your commits. You have a remote called dpl, which is upstream. So: $ git fetch dpl $ git pull --rebase dpl master $ git push origin <your branch> -f Note the -f, since you're overwriting remote history in your repo. -- - Alex
Mar 15 2012
next sibling parent reply =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= <xtzgzorex gmail.com> writes:
On 15-03-2012 21:49, H. S. Teoh wrote:
 On Thu, Mar 15, 2012 at 08:59:57PM +0100, Alex Rønne Petersen wrote:
 On 15-03-2012 20:13, H. S. Teoh wrote:
 I'm trying to submit a pull request for druntime, but I'm running into a
 git problem. This is what I did:

 - (I forgot that my master branch is out of date)
 - created a new branch for the fix and committed some changes
 - switched to master and ran 'git pull'
 - now master is ahead of the branch by a number of commits
 - switched back to branch
 - ran 'git rebase master' to pull in changes from master and apply my
    changes on top of it
 - checked that history looks clean
 - 'git push -u origin newbranch'
 - submit pull request: but now github thinks my branch has a whole bunch
    of commits I didn't make (looks like the commits made by rebase).

 So my question is, what did I do wrong, and what's the right way to
 pull in the latest changes from upstream without messing up the history?


 T

Let's say you're on your branch with your commits. You have a remote called dpl, which is upstream. So: $ git fetch dpl $ git pull --rebase dpl master $ git push origin<your branch> -f Note the -f, since you're overwriting remote history in your repo.

OK thanks! Another question. How to I repair my current history, which is all messed up now? That is, my branch has a whole bunch of commits I didn't make; how do I clean it up? Or is it easier to start from scratch? :) T

Well, it really depends on how the history looks... How many commits do you have? If it's a small number, just branch off upstream and cherry-pick each commit. -- - Alex
Mar 15 2012
next sibling parent =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= <xtzgzorex gmail.com> writes:
On 15-03-2012 22:37, H. S. Teoh wrote:
 On Thu, Mar 15, 2012 at 09:51:30PM +0100, Alex Rønne Petersen wrote:
 On 15-03-2012 21:49, H. S. Teoh wrote:

 Another question. How to I repair my current history, which is all
 messed up now? That is, my branch has a whole bunch of commits I didn't
 make; how do I clean it up? Or is it easier to start from scratch? :)


 T

Well, it really depends on how the history looks... How many commits do you have? If it's a small number, just branch off upstream and cherry-pick each commit.

OK, so I finally figured out how to repair it. Actually, I discovered that my origin/master branch was also broken (probably due to running the wrong git command in it in the past), because it had a bunch of commits from upstream that for some reason had different hashes (maybe the result of attempting to merge from a messed up branch?). This is probably why my topic branch was messed up in the first place, I think. So I did git reset --hard to clean up the history back to the point where it first starting diverging, then pulled from upstream/master (which I confirmed were fast-forward). Then I used `git push -f master` to clean up the history on github. So that takes care of master. Then in my topic branch, which had a messed up history: (branchpoint)---(fast-forwards from upstream)<-- master \ \---(merged)---(merged)---...---(my changes)<-- topic I did a `git rebase --onto master (my changes)`: (branchpoint)---(fast-forwards from upstream)<-- master \ \ \---(now unreachable commits) \--(my changes)<-- topic Then I used git push -f to cleanup the history on github. So now everything looks OK again. Phew! I did discover an interesting thing about git though... at one point in the cleanup process I accidentally reset 1 more commit than I had intended, and that commit had no other references to it (unreachable). But luckily I still had its hash available, so `git merge<hash>` managed to restore it. I guess old unreachable commits are still kept until you run git gc. So that's one of the times when you *don't* want to run git gc. :-) T

See also git reflog. It's a life-saver. -- - Alex
Mar 15 2012
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2012-03-16 04:52, James Miller wrote:
 Also, git-svn isn't actually that bad...

It is. You can't properly use git because you have to make sure it's compatible with svn, like linear history. If you don't have a linear history you're in big trouble. -- /Jacob Carlborg
Mar 16 2012
parent Jacob Carlborg <doob me.com> writes:
On 2012-03-16 09:08, Jonathan M Davis wrote:
 On Friday, March 16, 2012 08:52:47 Jacob Carlborg wrote:
 On 2012-03-16 04:52, James Miller wrote:
 Also, git-svn isn't actually that bad...

It is. You can't properly use git because you have to make sure it's compatible with svn, like linear history. If you don't have a linear history you're in big trouble.

Yeah. I use git-svn at work, because I like it a lot better than using pure svn, but it's _nowhere_ near as good as pure git. There are just too many features that you have to be careful with or avoid.

Exactly, you need to be very careful and follow a strict workflow to avoid breaking svn. -- /Jacob Carlborg
Mar 16 2012
prev sibling parent reply =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= <xtzgzorex gmail.com> writes:
On 15-03-2012 21:53, Gour wrote:
 On Thu, 15 Mar 2012 13:49:14 -0700
 "H. S. Teoh"<hsteoh quickfur.ath.cx>  wrote:

 Another question. How to I repair my current history, which is all
 messed up now?

By not using DVCS which allows you to rewrite history (hint: check Fossil). ;)

It's perfectly useful in DVCS. Without it, you'd have a mess of a history when you send your changes upstream. That's not really acceptable.
 Otoh, I do not know how much you are 'in love' wiht git, but maybe it
 would be possible to use hg-git to collaborate with D  github.


 Sincerely,
 Gour

-- - Alex
Mar 15 2012
parent reply Sean Cavanaugh <WorksOnMyMachine gmail.com> writes:
On 3/15/2012 3:56 PM, Alex Rønne Petersen wrote:
 On 15-03-2012 21:53, Gour wrote:
 On Thu, 15 Mar 2012 13:49:14 -0700
 "H. S. Teoh"<hsteoh quickfur.ath.cx> wrote:

 Another question. How to I repair my current history, which is all
 messed up now?

By not using DVCS which allows you to rewrite history (hint: check Fossil). ;)

It's perfectly useful in DVCS. Without it, you'd have a mess of a history when you send your changes upstream. That's not really acceptable.

Why would you delete history? Thats pretty much the primary purpose of source control.
Mar 15 2012
parent =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= <xtzgzorex gmail.com> writes:
On 15-03-2012 22:17, Sean Cavanaugh wrote:
 On 3/15/2012 3:56 PM, Alex Rønne Petersen wrote:
 On 15-03-2012 21:53, Gour wrote:
 On Thu, 15 Mar 2012 13:49:14 -0700
 "H. S. Teoh"<hsteoh quickfur.ath.cx> wrote:

 Another question. How to I repair my current history, which is all
 messed up now?

By not using DVCS which allows you to rewrite history (hint: check Fossil). ;)

It's perfectly useful in DVCS. Without it, you'd have a mess of a history when you send your changes upstream. That's not really acceptable.

Why would you delete history? Thats pretty much the primary purpose of source control.

I didn't say delete history. Squashing commits together into one just simplifies the history. It makes it easier to review, easier to view in logs, easier to bisect, ... -- - Alex
Mar 15 2012