Skip to content

Instantly share code, notes, and snippets.

@vio
Created February 16, 2018 15:23
Show Gist options
  • Save vio/df7fdc7286117c9326b345011885833f to your computer and use it in GitHub Desktop.
Save vio/df7fdc7286117c9326b345011885833f to your computer and use it in GitHub Desktop.

Git

Diff

Don't get the entire history

# get the truncated history:
git clone --depth 1

# or no checkout
git clone -n

# get only one branch:
git clone --branch NAME

Merge without a commit:

git merge v1.0 --no-commit --no-ff

Git bisect

git bisect start

# test
git bisect good / bad

Git rebase

git rebase HEAD~3 -i

transplant:

git rebase --onto NEW_REF_BRANCH OLD_REF_BRANCH CURRENT_BRANCH

Git subtree


git subtree add --prefix /some/prefix GIT_URL BRANCH_NAME

Git sparse checkout

# Init working copy
git init .

# Add remote origin
git remote add origin GIT_URL

# Enable sparse checkout
git config core.sparseCheckout true
echo 'FOLDER' > .git/info/sparse-checkout

git pull origin master

if we change .git/info/sparse-checkout:

git read-tree -m -u HEAD

Remove the last commit (not keeping the changes)

git reset --hard HEAD~1

to revert

git reflog
git reset --hard COMMITID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment