Skip to content

Instantly share code, notes, and snippets.

@nrninsane
Last active June 2, 2021 09:14
Show Gist options
  • Select an option

  • Save nrninsane/eb7d0fb69902072732d7a91e61d41f1a to your computer and use it in GitHub Desktop.

Select an option

Save nrninsane/eb7d0fb69902072732d7a91e61d41f1a to your computer and use it in GitHub Desktop.
git

Note: only rebase local branches, NEVER REBASE A REMOTE BRANCH.

  1. create backup to preserve original commit tree
git branch myBackup
  1. get list of commits and their SHA
git --no-pager log --oneline
  1. start interactive rebase on targetSHA
git rebase -i <targetSHA>^
  1. determine what to do with each commit & continue: keep, edit, etc. (git will show you the options)
  • to find recent dangling commit
git reflog
  • this dangling commit can be inserted back
git cherry-pick <hash>
  • to cherry-pick without automatically committing
git chery-pick -n <hash>

from https://coderwall.com/p/euwpig/a-better-git-log

configure

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"

usages:

  • git lg
  • git lg -p to see line changes

Tip: practice this on a throwaway project to get a better grasp.

  1. create a backup
git branch backup-in-case-of-screwup
  1. to split up the commit of current rebase step
git reset HEAD^
git stash save "split this up into multiple commits"
  1. make the changes
  • git stash apply
  • modify lines,
  • git add,
  • git commit
  1. get back the original state of the rebase step
git stash apply <myStash>
  1. repeat until nothing to commit

  2. if you are done with the current rebase step

git rebase --continue

if you want to abort rebase

git rebase --abort

if rebase finished and it was not what you wanted

git reset myBackup --hard
  • to include untracked files
git stash save --include-untracked "<myDescription>"
  • to include everything, even files/folders in .gitignore
git stash --all "<myDescription>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment