Skip to content

Instantly share code, notes, and snippets.

@johnbartholomew
Created October 28, 2012 21:15
Show Gist options
  • Save johnbartholomew/3969948 to your computer and use it in GitHub Desktop.
Save johnbartholomew/3969948 to your computer and use it in GitHub Desktop.
Some git instructions

This assumes you have no changes loose in your working copy.

At any point you can run gitk to view the commit history. I use gitk all the time, to view and search through the commit history, find the SHA1 hash of a particular commit, and check the commit graph.

First, make sure master is up to date (it most likely already is, but no harm in checking)

git checkout master
git fetch upstream
git merge --ff-only upstream/master

--ff-only tells git to only accept "fast-forward" merges. fast-fowarding doesn't create any new commits, it just moves you forward from your current commit to a direct descendant (I use it when I update master as an extra safety measure to ensure my local master hasn't diverged)

Create and switch to a new branch for the cleaned up commit series You've already done almost all the work in your integration/faction branch

git checkout -b faction-multigov-2 integration/faction

integration/faction is sitting on top of a commit that only existed for a couple of minutes before I amended it (my fault, and sorry again -- I'll be more strict about not doing that in future) To strip this out, we want to take the changes and recreate them on top of the current official master. The rebase command can do this (and in this case there shouldn't be any conflicts)

git rebase master

There are also a couple of commits (the ones you've helpfully marked DO NOT MERGE) that we can strip out. The rebase command can do this too:

git rebase --interactive master

This should give you some kind of text editor with a list of commits, each starting with "pick". This is sort of an edit list. When you close the editor, rebase will take each commit in the list. You can comment out lines, or change the action to be performed. Here we just want to comment out the two DO NOT MERGE commits so that rebase will skip them completely.

(these two rebase commands could have been done in one step, but I find it's best not to try to do too much in a single rebase, because it can get complicated)

Now the branch should be a clean series of commits starting from the up to date master.

Finally, you just want to point your existing feature/faction-multigov branch at the new commits. You can use reset to do this

git checkout feature/faction-multigov
git reset --hard faction-multigov-2

(there are several other ways you could do it too)

And push back up to github

git push --force origin feature/faction-multigov

The --force option tells git to accept the update even though the new commits aren't descendants of the old commits. Normally you don't need to use force (and it's safer not to use it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment