Skip to content

Instantly share code, notes, and snippets.

@roalcantara
Last active April 23, 2024 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roalcantara/341268e465788ac89c86e2fddf087f9c to your computer and use it in GitHub Desktop.
Save roalcantara/341268e465788ac89c86e2fddf087f9c to your computer and use it in GitHub Desktop.
Git commands
# to log oneliner
git log --color --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
# to log oneliner 2
git log --color --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit --date=iso-strict
# to change a specific commit
git rebase -i <HASH>
# to abort the rebase
git rebase --abort
# to continue the rebase
git rebase --continue
####### TO REWORD COMMITS
# 1. list all commits
git log --color --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
# 2. pick de hash of the commit after the one you whant to change and..
git rebase -i <HASH>
# 3. <I> move in front of the commit you wanna change, and replace p to w (this commit will be opened to be rewritten)
# 4. <ESC>:wq<ENTER> (save and exit)
# 5. <I> Type the new commit message
# 6. <ESC>:wq<ENTER> (save and exit)
####### TO MERGE (FIXUP) COMMITS
# 1. list all commits
git log --color --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
# 2. pick de hash of the commit after the one you whant to change and..
git rebase -i <HASH>
# 3. <I> move in front of the commit you wanna fixup, change p to f (this commit will me fixed witht the commit above it)
# 4. <ESC>:wq<ENTER> (save and exit)
####### TO DROP COMMITS
# 1. list all commits
git log --color --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
# 2. pick de hash of the commit after the one you whant to change and..
git rebase -i <HASH>
# 3. <I> move in front of the commit you wanna drop, change p to d (this commit will be dropped!)
# 4. <ESC>:wq<ENTER> (save and exit)
####### TO RE-ORDER COMMITS
# 1. list all commits
git log --color --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
# 2. pick de hash of the commit after the one you whant to change and..
git rebase -i <HASH>
# 3. <I> move in front of the commit you wanna reorder and <ESC><D><D> (this will cut the line to clipboard)
# 4. Go to the new line of the commit and <P> (this will paste the line from clipboard to the current line)
# 5. <ESC>:wq<ENTER> (save and exit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment