<commit_before> # -*- Mode: sh -*-

#################################### INIT ####################################
git config --global user.name "<NAME>"
git config --global user.email <EMAIL>
git config --global core.editor "emacs -nw"
git config --global color.ui true
git config --global core.excludesfile ~/.gitignore
git config --global --add pull.rebase true
git config --global --add push.default simple
git config --global --add branch.master.mergeoptions --squash
git config --global merge.tool <tool>
git config --global diff.tool <tool>
git config --global difftool.prompt false
# on windows
git config --system core.autocrlf input
# for magit: set environment variable
(setenv "GIT_SSH" "C:\Program Files\Portable PuTTY\plink.exe")

#add .gitignore patterns to .git/info/exclude.  These will not be checked in.

################################## REMOTES ###################################
# set username (for pushing)
git remote set-url origin <EMAIL>:username/repo.git

################################# BRANCHING ##################################
# checkout and track remote branch
git checkout --track origin/<branch>
# set existing branch to track remote
git branch -u origin/<branch>
git branch --track origin/<branch>
# push branch upstream
git push origin <local>[:<remote>]
# push branch upstream and set up tracking
git push -u origin <branch>
# delete local branch
git branch -d <branch>
# delete remote branch
git push origin :<branch>
# ensure master is up to date, without checking it out
git fetch --all
git fetch origin master:master
# list all branches created by me
git for-each-ref --format=' %(authorname) %09 %(refname)' | grep Harms
# point a fork back to its upstream for a pull request
git remote add upstream <EMAIL>:proj/name.git

git clean -dfx

#################################### DIFF ####################################
# name and status only
git diff --name-status
# show change magnitude
git diff --stat
# highlight word differences
git diff --word-diff=color
git diff --color-words[=<regex>]
# changes between 2 branches
git diff topic master
git diff topic..master
# changes on master since topic was branched off
git diff topic...master
# changes to a file since master
git diff master -- /path/to/file
# changes to a file between HEAD and master
git diff master.. path/to/file
# changes to a file between 2 branches
git diff branch1 branch2 -- path/to/file

################################ VIEW COMMITS ################################
# VIEW COMMITS [plus files changed / patches ]
git log --oneline --decorate --graph [--stat/p]
# view commits on feature branch not on master
git log master..feature
git log ^master feature
# view commits on A or B but not C
git log A B ^C
# view what is in master or feature but not common to them
git log --left-right master...feature
# view what I would push to a remote
git log origin/master..HEAD
# PARENT SELECTOR: first/second parent of HEAD
HEAD^    /    HEAD^2
# GRANDPARENT SELECTOR (depth-first) / 2nd ancestor
HEAD~    /    HEAD~2
# view all commits affecting file(s)
git log --follow -- file1 [file2]
# search commits for a string (pickaxe)
git log -S"string"
# search commits for a regex
git log -G"regex"
# group commits by author [sort by number of commits]
git shortlog [-n]
# committer name, hash, date
git log --pretty=format:"%cn committed %h on %cd"
# other options (incomplete)
 --after="2014-7-1" --before="yesterday" --after="2 weeks ago"
 --author="John\|<EMAIL>"
 --grep="JIRA-.*"

#################################### SHOW ####################################
git show origin/<branch>:path/from/root/to/file
git show origin/<branch>:./relative/path/to/file

################################### COMMIT ###################################
# change last commit
git commit --amend

################################### SQUASH ###################################
# squash last 4 commits
git rebase -i HEAD~4
# edit an old commit
git rebase -i HEAD~4
git commit --amend
git rebase --continue
# merge feature branch using one big commit
git merge master                # into feature first
git checkout master
git merge --squash <feature>
# ...which is equivalent to:
git checkout <feature>
git diff main > feature.patch
git checkout main
git apply feature.patch
git add .

################################# SUBMODULE ##################################
# update a submodule
cd sub
git pull origin master
cd ..; git status
git add sub
git commit -m "updated submodule sub"

################################### STASH ####################################
git stash <show|save|drop|push|pop> stash@\{0\}
# selectively stage
git stash save -p "name of stash"
# interactively staging hunks:
"y:stage n:don't stage a:all-in-file d:skip-file q:quit"

################################ CHERRY-PICK #################################
# cherry-pick a commit without committing (index need not match HEAD)
git cherry-pick -n <sha>

################################### PATCH ####################################
# create patch from last revision
git format-patch HEAD~
# create patch from arbitrary revision (only that revision)
git format-patch -1 <sha>
# create patch from working files
git diff [--cached] > some.patch
# apply patch to working directory
git apply [--check] [--reject] some.patch
# directly commit a patch
git am some.patch<commit_msg>update git docs for bundles<commit_after> # -*- Mode: sh -*-

#################################### INIT ####################################
git config --global user.name "<NAME>"
git config --global user.email <EMAIL>
git config --global core.editor "emacs -nw"
git config --global color.ui true
git config --global core.excludesfile ~/.gitignore
git config --global --add pull.rebase true
git config --global --add push.default simple
git config --global --add branch.master.mergeoptions --squash
git config --global merge.tool <tool>
git config --global diff.tool <tool>
git config --global difftool.prompt false
# on windows
git config --system core.autocrlf input
# for magit: set environment variable
(setenv "GIT_SSH" "C:\Program Files\Portable PuTTY\plink.exe")

#add .gitignore patterns to .git/info/exclude.  These will not be checked in.

################################## REMOTES ###################################
# set username (for pushing)
git remote set-url origin <EMAIL>:username/repo.git

################################# BRANCHING ##################################
# checkout and track remote branch
git checkout --track origin/<branch>
# set existing branch to track remote
git branch -u origin/<branch>
git branch --track origin/<branch>
# push branch upstream
git push origin <local>[:<remote>]
# push branch upstream and set up tracking
git push -u origin <branch>
# delete local branch
git branch -d <branch>
# delete remote branch
git push origin :<branch>
# ensure master is up to date, without checking it out
git fetch --all
git fetch origin master:master
# list all branches created by me
git for-each-ref --format=' %(authorname) %09 %(refname)' | grep Harms
# point a fork back to its upstream for a pull request
git remote add upstream <EMAIL>:proj/name.git

git clean -dfx

#################################### DIFF ####################################
# name and status only
git diff --name-status
# show change magnitude
git diff --stat
# highlight word differences
git diff --word-diff=color
git diff --color-words[=<regex>]
# changes between 2 branches
git diff topic master
git diff topic..master
# changes on master since topic was branched off
git diff topic...master
# changes to a file since master
git diff master -- /path/to/file
# changes to a file between HEAD and master
git diff master.. path/to/file
# changes to a file between 2 branches
git diff branch1 branch2 -- path/to/file

################################ VIEW COMMITS ################################
# VIEW COMMITS [plus files changed / patches ]
git log --oneline --decorate --graph [--stat/p]
# view commits on feature branch not on master
git log master..feature
git log ^master feature
# view commits on A or B but not C
git log A B ^C
# view what is in master or feature but not common to them
git log --left-right master...feature
# view what I would push to a remote
git log origin/master..HEAD
# PARENT SELECTOR: first/second parent of HEAD
HEAD^    /    HEAD^2
# GRANDPARENT SELECTOR (depth-first) / 2nd ancestor
HEAD~    /    HEAD~2
# view all commits affecting file(s)
git log --follow -- file1 [file2]
# search commits for a string (pickaxe)
git log -S"string"
# search commits for a regex
git log -G"regex"
# group commits by author [sort by number of commits]
git shortlog [-n]
# committer name, hash, date
git log --pretty=format:"%cn committed %h on %cd"
# other options (incomplete)
 --after="2014-7-1" --before="yesterday" --after="2 weeks ago"
 --author="John\|<EMAIL>"
 --grep="JIRA-.*"

#################################### SHOW ####################################
git show origin/<branch>:path/from/root/to/file
git show origin/<branch>:./relative/path/to/file

################################### COMMIT ###################################
# change last commit
git commit --amend

################################### SQUASH ###################################
# squash last 4 commits
git rebase -i HEAD~4
# edit an old commit
git rebase -i HEAD~4
git commit --amend
git rebase --continue
# merge feature branch using one big commit
git merge master                # into feature first
git checkout master
git merge --squash <feature>
# ...which is equivalent to:
git checkout <feature>
git diff main > feature.patch
git checkout main
git apply feature.patch
git add .

################################# SUBMODULE ##################################
# update a submodule
cd sub
git pull origin master
cd ..; git status
git add sub
git commit -m "updated submodule sub"

################################### STASH ####################################
git stash <show|save|drop|push|pop> stash@\{0\}
# selectively stage
git stash save -p "name of stash"
# interactively staging hunks:
"y:stage n:don't stage a:all-in-file d:skip-file q:quit"

################################ CHERRY-PICK #################################
# cherry-pick a commit without committing (index need not match HEAD)
git cherry-pick -n <sha>

################################### PATCH ####################################
# create patch from last revision
git format-patch HEAD~
# create patch from arbitrary revision (only that revision)
git format-patch -1 <sha>
# create patch from working files
git diff [--cached] > some.patch
# apply patch to working directory
git apply [--check] [--reject] some.patch
# directly commit a patch
git am some.patch

################################### BUNDLE ###################################
# create a bundle
git bundle create repo.bundle master
# use a bundle
git clone repo.bundle -b master repo
{'fraction_non_alphanumeric': 0.2416704910509408, 'fraction_numerical': 0.004222120238641579, 'mean_word_length': 4.573401534526854, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1005954', 'n_tokens_mistral': 3010, 'n_tokens_neox': 2841, 'n_words': 1251}