git help
From Wikistix
Cheat-sheet of discoveries, many mined from stackoverflow.
Show unpushed commits
One branch
git log remote/pkgsrc-2018Q3..pkgsrc-2018Q3
git diff remote/pkgsrc-2018Q3..pkgsrc-2018Q3
All branches
git log --branches --not --remotes
Show diffs for a single commit (relative to its ancestor)
git diff dcca4290b0cafd64cc80a9ca7c63dc2e8228ae8d~ dcca4290b0cafd64cc80a9ca7c63dc2e8228ae8d
Generate a patch file for a single commit
git format-patch --stdout -1 e13535f822b5efe0e3b471bc366e8d3ea96059d5
Show diffs for a stash
For the latest stash
git stash show -p
For a given stash
git stash show -p stash@{1}
Including untracked files
git stash show -p -u
Pop untracked files after stash apply merge conflict
git stash pop
… merge conflicts, untracked files not created …
git checkout stash^3 -- . # only works with clean index
git stash drop # remove the stash
Record intent to add (allowing diffs of untracked files)
git add -N <file> …
Use the following to revert:
git restore --staged <file> …
Resolve "deleted by us" unmerged paths
Deletes the file from the repositories point of view and unstages the existing file:
git reset HEAD <file> …
Show file history for all branches
git log --all <file>
Patch local tree with a commit from another branch
git cherry-pick -n <commit-hash>
Undo a commit
NOTE: this almost permanently deletes the commit.
git reset --hard <commit>~
Add a new worktree, sharing an existing git repository
git worktree add ../newpath mybranch
git worktree add ../../netbsd-9/src netbsd-9
Update a worktree from the local git repository without pulling from the remote
git status
…
On branch foo
Your branch is behind 'origin/foo' by 135 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
…
git rebase
Successfully rebased and updated refs/heads/foo.
Get/Set origin, https or ssh
git remote get-url origin
git remote set-url origin git@github.com:NetBSD/src.git
git remote set-url origin https://github.com/NetBSD/src.git
Get/Set config vars, like the current pager
git config --get core.pager
git config core.pager 'less -RX'
git config --get pull.rebase
git config pull.rebase true