Skip to content

Instantly share code, notes, and snippets.

@mikenairn
Last active August 29, 2015 14:04
Show Gist options
  • Save mikenairn/c8fdedc420d24d5f891f to your computer and use it in GitHub Desktop.
Save mikenairn/c8fdedc420d24d5f891f to your computer and use it in GitHub Desktop.
Git rebase

Update all remotes

git fetch --all

Change to my branch

git checkout 995-nagios-check-fordyno-volume-group

List changes on my branch not on master

git log origin/master..HEAD --pretty=oneline
3832321972b243f8a4e3b8b86712c4fc515f0514 Updated Dyno volume group check with new nagios service. Removed fh-svc-disk-lvm
fb912c62eb2d4e17995080ef454580a1330317e0 Updated Dyno volume group check with new nagios service. Removed fh-svc-disk-lvm
5eaf51327f305f661221a10ae7882d835cd5bb2a Updated Dyno volume group check with new nagios service. Removed fh-svc-disk-lvm
784b8de5d4981b5cc088b77b62a9d29e8681604d Updated Dyno volumen group check with new nagios service. Removed fh-svc-disk-lvm

4 commits here for a single change, these should be squashed into one.

git rebase -i HEAD~4

Your default editor will open, you change the options on the left of each commit. Set s(squash) for each below the first i.e. Squash all commits into the first one and save (wq!). Note, you can also move commits around during this step, the order that the commits are in the list, is the order that they will be re-applied in. This allows you to squash similar commits that are not necessarily commited in order.

pick 784b8de Updated Dyno volumen group check with new nagios service. Removed fh-svc-disk-lvm
s 5eaf513 Updated Dyno volume group check with new nagios service. Removed fh-svc-disk-lvm
s fb912c6 Updated Dyno volume group check with new nagios service. Removed fh-svc-disk-lvm
s 3832321 Updated Dyno volume group check with new nagios service. Removed fh-svc-disk-lvm

# Rebase 7352ecf..3832321 onto 7352ecf
#
...

You will be asked to sort the description for the commit, delete as appropriate and save again

# This is a combination of 4 commits.
# The first commit's message is:
Updated Dyno volume group check with new nagios service. Removed fh-svc-disk-lvm

Check the result

git log origin/master..HEAD --pretty=oneline
2343e15c7f63923893a79659fa372687ba6a7477 Updated Dyno volumen group check with new nagios service. Removed fh-svc-disk-lvm

You now have one commit instead of four.

You will need to force update your remote branch if you already created one

git push origin 995-nagios-check-fordyno-volume-group -f

If you are sharing the remote branch with anyone else you will need to inform that they need to reset there local copy of the branch.

git fetch --all
git checkout 995-nagios-check-fordyno-volume-group 
git reset --hard origin/995-nagios-check-fordyno-volume-group  

@ciaran-byrne
Copy link

Should the force update not be this instead?

git push origin 995-nagios-check-fordyno-volume-group -f 

@mikenairn
Copy link
Author

yep, fixed now.

@jasonmadigan
Copy link

@mikenairn - I assume for people who've checked out your branch before you rebased and force pushed, they'll need to reset --hard their local branch?

@mikenairn
Copy link
Author

@jasonmadigan - Yes if you force pushed a branch and someone has pulled it before hand, they will have to hard reset there local branch. Most things we do nobody shares branches in this way, but if you are you will have to communicate with everyone using it what you are doing.

Updated gist accordingly.

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