Skip to content

Instantly share code, notes, and snippets.

@cbecker
Last active December 9, 2021 11:26
Show Gist options
  • Save cbecker/b347f50e567830cbc8b0746b2786194f to your computer and use it in GitHub Desktop.
Save cbecker/b347f50e567830cbc8b0746b2786194f to your computer and use it in GitHub Desktop.
Git related

Amazing tutorial and resource

http://learngitbranching.js.org/

Search content on all commits

git grep -p '<whatever>' $(git rev-list --all)

Get file from branch B2 into branch B1

git checkout B1
git checkout B2 -- path/to/file

Delete a commit between other commits (rebase)

If we have commits A-B-C-D, and we want to remove C,

git rebase -i HEAD~3

will show the last 3 commits, then we can just delete the commit we want in vim by deleting the respective line, and save.

Make branch point to specific commit

git branch -f branchname commit

Rebasing branch B2 wrt branch B1

git rebase --onto B1 'B1@{1}' B2

Rebase range of commits in branch B2 (cherry-pick) wrt branch B1

git checkout B2 # check out working branch

git checkout -b tempBranch

git rebase --onto B1 commitHash^ tempBranch

git checkout B2 && git reset --hard tempBranch

Create branch at current head

git checkout -B newBranchName HEAD

Merge upstream into local so that local reflects upstream exactly

git checkout upstream

git symbolic-ref HEAD refs/heads/local

# go to git gui, or just commit the changes

Reset and Revert

git reset <where to reset to> is for local branches

git revert <which commit to revert> for remote branches.

NOTE that the arguments are not the same!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment