Last active
January 13, 2020 02:22
-
-
Save khaije1/3183937 to your computer and use it in GitHub Desktop.
fun w/ git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# .gitignore - inhibit git from tracking files matching the below patterns | |
# | |
# | |
# for directory tracking, add empty .gitignore to example/. | |
!.gitignore | |
!.gitkeep | |
# file browser metadata/artifacts | |
.DS_Store | |
.directory | |
# alt/aux version control tracking artifacts | |
.svn | |
# alt/aux tooling artifacts | |
.vagrant | |
# ignore secret/personal stuffs (except example files) | |
*.gpg | |
*.asc | |
.secret.d/*/* | |
!*__example | |
# unnecesary autosaves/backups | |
*~ | |
*\#* | |
auto-save-list/* | |
~$* | |
.swp | |
*.swp | |
# temp ao cache files | |
var/*/* | |
tmp/* | |
# compiled ao binary | |
*.pyc | |
*.elc | |
*.o | |
*.a | |
*.jar | |
*.exe | |
*.obj | |
*.dll | |
*.class | |
# temp files | |
*\#* | |
*~ | |
*.log | |
# MSVS project files | |
**/Debug/ | |
**/Release/ | |
**/Backup/ | |
**/elog/ | |
*.v11.suo | |
*.sdf | |
*.opensdf | |
# intelisense db | |
*.ncb | |
*.idb | |
*.pdb | |
#*.unsuccessfulbuild | |
#*.lastbuildstate | |
#*.vcxproj | |
#*.vcxproj.filters | |
#*.tlog | |
#*.log | |
#*.intermediate.manifest | |
#*.exp | |
#*.sdf | |
# never ignore these | |
!**/Utilities/** | |
!**/.gitkeep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# init | |
git init . | |
git commit -m"init commit" --allow-empty | |
git push --set-upstream origin master:master | |
git annex init <device-label> | |
# ^^ checks out branch annex/direct/master | |
git annex trust origin | |
git annex merge | |
git annex sync | |
# nb, git-annex.exe spawns several git.exe process | |
# nb, git-annex assistant will spawn a background ssh.exe to your origin remote | |
# nb, .git/annex/url is the URL for the webapps, great for monitoring activity, (since assistant --foreground is a bit dull) whee! | |
# EM on login: [Windows Scripting Host]"Can not find script file "C:Program Files(x86)\Git\git-annex-autostart.vbs" | |
# EM on 'git annex trust origin' | |
""" | |
Remote origin does not have git-annex installed; setting annex-ignore | |
This could be a problem with the git-annex installation on the remote. Please make sure that git-annex-shell is available in PATH when you ssh into the remote. Once you have fixed the git-annex installation, run: git config remote.origin.annex-ignore false | |
git-annex: cannot determine uuid for origin | |
""" | |
# nb, use git annex vicfg to edit configs | |
# nb, schedule jobs w/ : git annex schedule <remote> <expr> | |
# nb, prune git-annex history : git annex forget | |
# nb, sync / merge ... push local changes to remote, pull remote changes to local (respectively) | |
# nb, other notable command/options: webapp, watch, mirror <path> , assistant, dead <remote> , unannex <path>, status | |
# to sensibly add contents to git /o git-annex, (ex. binary files larger than 400k) | |
find * -type f -size +400k -exec grep -ILhq '.' {} \; -exec git annex add {} \; | |
# -or- | |
git config --global annex.largefiles "largerthan=300kb and not (include=*.c or include=*.h)" | |
# then, add matching files to the annex | |
git annex --auto add | |
# git annex assistant will automatically add non-matching files to git | |
git annex assistant | |
#nb, mysgit doesn't include 'file' cmd, alternatively to distinguish bin from text files, check for a null-byte w/i the first 1k, this would only occur in a binary file | |
# - Q: how to do this on msysgit: | |
# - w/ head and grep (there's no dd), nope just grep | |
# - A: grep '.' -ILhq <file> # opts: treat binary files as non-matches, only succeed on non-matches, quiet output | |
# nb, remotedaemon looks neat, it watches remotes for changes to pull |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -x | |
# be careful not to pollute stdin prior to catching it here | |
cmd_git="${cmd_git:-git}" | |
obj=$(cat - | ${cmd_git} hash-object -w --stdin) | |
# ENV-overridable variables | |
msg_usage=" | |
mysqldump | env uri_file='msyql-dump.sql.bkup' branch="mysql_bkup" cmd_git='git --git-dir=${HOME}/.extrefs/sql_bkup.git --work-tree=/tmp' ~/bin/git-stdin.sh | |
" | |
uri_file="${uri_file:-unnamed_file}" | |
branch="${branch:-master}" | |
obj_mode="${obj_mode:-100644}" | |
### functions | |
switch_branch(){ | |
local tmp_branch="${1:-$branch}" | |
#+NB: if symbolic-refs succeeds, reset index to HEAD else it's HEAD@{1} | |
#+TODO: test that $tmp_branch is ok | |
git symbolic-ref HEAD refs/heads/${tmp_branch} &>/dev/null | |
[[ 0 -eq $? ]] && ${cmd_git} reset --mixed &>/dev/null | |
} | |
### main | |
switch_branch | |
${cmd_git} update-index --add --cacheinfo ${obj_mode} ${obj} "${uri_file:-default_name}" | |
parent=$(${cmd_git} rev-parse "${branch}^{commit}" 2>/dev/null) | |
#if [[ -n $parent ]] ;then unset parent ;fi | |
#+TODO: fix write-tree, '-m text' message not working | |
#message="backup commit" | |
#+NB: for write-tree, tree must come before options | |
${cmd_git} update-ref "refs/heads/${branch}" $(${cmd_git} commit-tree $(${cmd_git} write-tree) ${message:+ -m $message} ${parent:+ -p $parent} ;) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# git config - http://kernel.org/pub/software/scm/git/docs/git-config.html | |
# don't run the whole thing, rather it's likely best to copy/paste/pluck targeted lines | |
# identity | |
#git config --global user.name "niklauz" | |
#git config --global user.email [email protected] | |
#git config --global user.signingkey <gpg-key-id> | |
# github authinfo | |
#git config --global github.user khaije1 | |
#git config --global github.token <see-github-profile> #secret!! | |
# aliases | |
git config --global alias.stash-unapply '! git stash show -p | git apply -R' | |
git config --global alias.unstage "! git reset HEAD --" #nb: run w/o file args will reset entire index to HEAD | |
git config --global alias.undo-commit "! git reset --soft HEAD^" | |
git config --global alias.ls "! test -x $(which git-annex) && git annex find --include '*' 2>/dev/null ; git ls-files -mustdock ; git status -sb " | |
git config --global alias.logm "! git log --graph --pretty --decorate --color --date=relative --tags --submodule=log --find-copies-harder --stat HEAD" #--notes --cherry-mark | |
git config --global alias.logl "! git log --graph --decorate --color --tags --oneline --all --cherry-mark -- " | |
git config --global alias.last "cat-file commit HEAD" | |
git config --global alias.st "! git status -sb && [[ $(which git-annex) ]] && git annex find '*'" | |
git config --global alias.br branch | |
git config --global alias.co checkout | |
git config --global alias.mt mergetool | |
# environment defaults | |
git config --global core.editor "emacs -nw" #Changing your Editor | |
git config --global color.ui true #Adding Color, See all color.* options in the git config docs | |
git config --global help.autocorrect 120 #Ignore Typos | |
# merge | |
git config --global merge.defaultToUpstream true | |
git config --global rerere.enabled 1 #activate the RE-use REcorded merge REsolution option | |
git config --global mergetool.keepBackup false #if false git mergetool will remove tempfiles after successful merge | |
git config --global merge.tool emerge | |
# credential helper/cache , http://git-scm.com/docs/git-credential-cache.html | |
#git config --global credential.helper cache # (default: 5mins) | |
#git config --global credential.helper 'cache --timeout=900' # set timeout to 15 mins | |
git config --global credential.helper 'cache --timeout=10800' # set timeout to 3hrs | |
# Other Config Options | |
# There are also a number of interesting options for packing, gc-ing, merging, remotes, branches, http transport, | |
# diffs, paging, whitespace and more. If you want to tweak these, check out the git config docs. | |
# git-annex | |
git config --global annex.largefiles "(largerthan=400kb)and(not(mimetype=\"text/*\"))" | |
git config --global annex.addsmallfiles false | |
# working w/ large files | |
#git verify-pack -v .git/objects/pack/pack-*.idx | grep blob | sort -k3nr | head | while read s x b x; do git rev-list --all --objects | grep $s | awk '{print "'"$b"'",$0;}'; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PROBLEMS | |
none | |
OUTCOMES | |
No problems encountered | |
OUTLOOK | |
- Nothing major - FWIW git-annex is working toward a big release in upcoming mo/yrs. It doesn't look like what I've tested, (the basics), will change but there may be some new capabilities/interactions of potential interest to examine and account for. | |
- I may wish to add to documentation on one side of another to ease setup. It's all as it should be, just possibly unanticipated by those unfamiliar with git-annex. | |
- *NB* git-annex support in gitolite is stable in every case I've tested, however there is a significant case that I have been unable to test for one simple reason: I don't understand the situation well enough to test it. This untested case is described below. | |
- Case Description | |
- USER desires that git-annex have two remotes: a bup remote and a (gitolite) git remote | |
- USER desires to move data from the bup repo, through git-annex, to gitolite | |
- USER expects the above process to be lossless as described and in reverse, i.e to creating a new bup repo, perhaps using git-annex, using only data sourced from gitolite without loss of data or feature-capability | |
- Case Analysis & Questions | |
- bup introduces a meta-packfile, (i.e. it is not native to git) | |
- git-annex evidently handles bup's non-standard-git files, is this communicated in a git-standard way to gitolite? If so, how? | |
- Additionally, I have not tested git-annex support in gitolite in the case where the git-annex 'assistant' functionality is used. | |
STATUS | |
- DONE test basic functionality with gitolite v3 core | |
- DONE patch lines mentioned in 'PROBLEMS' | |
- DONE test remaining functionality with git annex (refex specs, acl, get, copy, etc) | |
- NEXT test different annex special remotes(there are many, are all expected to work?): bup, rsync, directory, etc. | |
- though untested and thus unclear, if any of the above cases are determined to be non-compatible could it be deemed an acceptable functional constraint and not a "blocker"? | |
- to better document any capabilities/limitations it's appropriate to wait for the outcomes of these final steps, if only to produce more accurate expectations and/or documentation. Ideally someone who understands this well could address the underlying technical principles in clarifying what should be reasonably possible and/or reasonably expected. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
merging branches, while controlling history, is easier than I realized w/ 'git merge --squash' | |
it's great for cleanly merging work from a testing branch into a parent branch | |
before I was | |
(1) checking out a branch, then | |
(2) checking out the path of another branch with 'git co -- .' to get update the working-dir without moving HEAD then | |
(3) unstaging everything so that the index would return to the HEAD commit | |
from there I would | |
(4) merge the working-tree into the index to satisfaction, committing as I go | |
finishing with a | |
(5) 'git reset && git clean -df' to remove any changes that I still didn't want | |
Instead... I should have been using 'git merge --squash' | |
It's the same basic process but with much more manageable actions. | |
(1) 'git merge --squash <commitish>' merges (w/o making a commit) the commitish's state in to the index and working tree, showing a --stat style summary | |
(2) 'git save stash --keep-index --include-untracked' saves the changeset w/o removing it | |
(3) make commits by strategicly adding ('git add -p') from the index (or the stash) | |
(4) 'git reset && git clean -df && git stash drop' to cleanup when finished | |
so now I add hunks for what I want for each commit, and just whittle away from the stash as I want, even switching branches to distribute specific changes without having to redo the process... (also potentially useful for regression testing) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If I do this often I like to setup aliases as such: | |
alias git.centralrepo01="git --git-dir=/srv/repo/centralrepo01 --work-tree=/srv/repo/centralrepo01" | |
This can obviously be extended to great effect. For example I use it to access/maintain remote content under a local repo with a different username: | |
alias git.backupscripts="sudo -u backup -s git --git-dir=$HOME/tmp/bkup/scripts --work-tree=/var/backups/.scripts" | |
on most systems these will tab-complete and allow for: | |
git<tab><tab> | |
: git git. | |
git.<tab><tab> | |
: git.centralrepo01 git.backupscripts | |
git.c<tab> | |
: git.centralrepo01 | |
git.centralrepo01 status | |
: <will show status of wd vs HEAD> | |
when combined with other git config.alias commands this can be really useful! | |
I'm looking at ways to use this to backup databases directly, (w/o temp files). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment