Skip to content

Instantly share code, notes, and snippets.

@piascwal
Last active October 31, 2019 14:39
Show Gist options
  • Save piascwal/f2fa6eba741520ae0eacefd17a6ebb46 to your computer and use it in GitHub Desktop.
Save piascwal/f2fa6eba741520ae0eacefd17a6ebb46 to your computer and use it in GitHub Desktop.

Config for a pretty git log

git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"  

Use

git lg

How to merge a branch into master witch was checkouted from another already merged branch

Here we have developed a great feature in a branch (branch-a) that is waiting for review. The problem is that the new feature to develop now needs the feature developed on the branch-a. For that we have to pull a new branch-b from the last branch-a commit.

After a while comes the time to merge the branch-b. While branch-a has been merging for days and other branches have been merged into master ... how not to spend my day trying to merge branch-b into maser ?

Here a representation of our problem:

             -------y1----y2---y3---              branch-b
           / 
 ----x1---x2---                                   branch-a
/               \
------------------------------------------------- master

Display logs

git lg

Find the commits to squash (here it is y1, y2 ans y3) and select the previous commit (here it is x2)

* y3 - my y3 commit
* y2 - my y2 commit
* y1 - my y1 commit
* x2 - my x2 commit
* x1 - my x1 commit
* t2m - my commit for t2 merged branche
|\  
| * t2 - my t2 commit 
|/  
* t1m - my commit for t1 merged branche
|\  
| * t1 - my t1 commit 
|/  

Rebase interactive from the previous commit of the first commit to squash

git rebase -i x2

pick first commit et squash others

p y1
s y2
s y3

save :wq
save new commit message :wq

Check the logs

git lg

Your y1, y2, y3 are now replaced by a new commit ( ynew )

* ynew - my squash commit containing y1 y2 y3
* x2 - my x2 commit
* x1 - my x1 commit
* t2m - my commit for t2 merged branche
|\  
| * t2 - my t2 commit 
|/  
* t1m - my commit for t1 merged branche
|\  
| * t1 - my t1 commit 
|/  

Go back to master and pull

git checkout master
git pull

Checkout a new branch

git checkout -b branch-b-2

Apply the changes on the new branch introduced by ynew with cherry pick command

git cherry-pick ynew

resolve conflict with your favorite tools

commit (No message needed)
git commit

update submodule

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