Skip to content

Instantly share code, notes, and snippets.

@sureshnath
Last active June 9, 2020 17:08
Show Gist options
  • Save sureshnath/8798ab275dec02ecb0ff43b01f35ae6b to your computer and use it in GitHub Desktop.
Save sureshnath/8798ab275dec02ecb0ff43b01f35ae6b to your computer and use it in GitHub Desktop.
git useful commands
# to see commit logs with short commit hash
git log --pretty=reference
# to pick and squash multiple commits
git rebase --interactive [commit-hash]
# nice explanation available in https://www.internalpointers.com/post/squash-commits-into-one-git
# sparse checkout set root .gitignore and followed but any folder seperated by space
git sparse-checkout set //.gitignore
# https://stackoverflow.com/questions/1628563/move-the-most-recent-commits-to-a-new-branch-with-git
# move last commits to existing branch
git checkout existingbranch
git merge master # Bring the commits here
git checkout master
git reset --keep HEAD~3 # Move master back by 3 commits.
git checkout existingbranch
# move last commits to new branch
git branch newbranch # Create a new branch, containing all current commits
git reset --keep HEAD~3 # Move master back by 3 commits (Make sure you know how many commits you need to go back)
git checkout newbranch # Go to the new branch that still has the desired commits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment