Skip to content

Instantly share code, notes, and snippets.

@ChoiZ
Last active January 18, 2016 13:27
Show Gist options
  • Save ChoiZ/07dae77a82fde20c9245 to your computer and use it in GitHub Desktop.
Save ChoiZ/07dae77a82fde20c9245 to your computer and use it in GitHub Desktop.
Usefull git commands

Usefull git commands

Add a specific commit to current branch:

git cherry-pick commit-hash

Merge commits

Merge the last 2 commits:

git rebase -i @~2

(old git version you must use HEAD instead of @)

git rebase -i HEAD^2
pick 8a527db Fix coding standard
pick 0721a90 Implement new method NewMethod()

Use "pick" for the first line and change the second "pick" by "s" or "squash" to use the commit and meld into previous one.

pick 8a527db Fix coding standard
s 0721a90 Implement new method NewMethod()

Then save and quit the file and update the commit message.

Rewrite / change date

Rewrite last commit:

git commit --amend

Commit with another date or time:

git commit --date="Tue Dec 8 2015 12:12:12 CET"

Rewrite last commit and change date to Tue Dec 8 2015 12:12:12 CET:

git commit --amend --date="Tue Dec 8 2015 12:12:12 CET"

Patch

Patch last commit:

git format-patch -n @^1

(old git version you must use HEAD instead of @)

git format-patch -n HEAD^1

Apply patch:

git am 0001-commit-message.patch

Submodule

Init && update

git submodule update --init

Foreach submodule pull origin master

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