A Quick Git reminder. This will grow as I go.
$ <in>git config --global user.name "Olivier Mehani"</in> $ <in>git config --global user.email me@example.com</in>
$ <in>git config --global credential.helper cache</in>
$ <in>git config --global color.ui auto</in>
As explained here, a diff3
style for conflicts shows both parents, thus allowing to understand the conflict and fix it better. Also, vimdiff
is good.
$ <in>git config --global merge.conflictstyle diff3</in> $ <in>git config --global merge.tool vimdiff</in>
The easiest (i.e. almost one line) solution is
$ <in>git checkout --orphan $NEWBRANCH; git rm -rf .</in>
Another, more tedious way of doing it, by pointing HEAD
to a non-existing branch, and removing the current index so nothing is staged yet. As seen here.
$ <in>git symbolic-ref HEAD refs/heads/$NEWBRANCH</in> $ <in>rm .git/index</in>
As seen here:
$ <in>git grep <regexp> $(git rev-list --all)</in>
Using git filter-branch(1), or BFG. Also, see here.
$ <in>git filter-branch --force --prune-empty --tree-filter "rm -f UNWANTEDFILE"</in> $ <in>git reflog expire --expire=all</in> # Forget references to previous checkouts $ <in></in>
As seen here:
You can remove the file objects. Just unpack any packs and rm .git/objects/12/345… Use git show to walk from > commit to tree to file.
git fsck will complain about it forever, of course.
Alternatively, wait for sha1 to be fully broken…
As explained in git-filter-branch(1), via Zrajm.
$ <in>SUBDIR_NAME="the\/subdir"</in> $ <in>BRANCH_NAME=newbranch</in> $ <in>git filter-branch --index-filter \ 'git ls-files -s | \ sed "s-\t-&'"$SUBDIR_NAME"'/-" | \ GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && \ mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE ' "$BRANCH_NAME"</in>
Using git-format-patch
and git-am
, adapted from here.
src$ <in>export PATHS=dir1/ dir2/file</in> src$ <in>git format-patch $(git log --oneline $PATHS | sed 's/ .*//' | tail -n 1)^..HEAD $PATHS</in> src$ <in>cd $DST</in> dst$ <in>git am $SRC/*.patch</in>
If paths are clean subdirectories, git subtree
can be of use.
In case of
Cloning into 'latex-makefile'... fatal: unable to access 'https://scm.narf.ssji.net/git/latex-makefile/': SSL certificate problem: Invalid certificate chain Clone of 'https://scm.narf.ssji.net/git/latex-makefile/' into submodule path 'latex-makefile' failed
git config http.sslVerify false
should have worked, but
GIT_SSL_NO_VERIFY=true git [clone|submodule...]
definitely did.
As discussed here.
$ <in>export GASERVER=server</in> $ <in>export GAUSER=user</in> $ <in>export GAPATH=/path</in> $ <in>export GASANEPATH=${GAPATH//\//.2F}</in> $ <in>export GASSHHOSTNAME=${GASERVER}-${GAUSER}_${GASANEPATH}</in> $ <in>ssh-keygen -t rsa -f ~/.ssh/git-annex/key.git-annex-$GASSHHOSTNAME</in> $ <in>cat << EOF >> ~/.ssh/config # Added manually for git-annex Host git-annex-$GASSHHOSTNAME Hostname $GASERVER IdentityFile ~/.ssh/git-annex/key.git-annex-$GASSHHOSTNAME IdentitiesOnly yes StrictHostKeyChecking yes EOF</in> $ <in>ssh-copy-id -i ~/.ssh/git-annex/key.git-annex-$GASSHHOSTNAME $GAUSER@$GASERVER</in> $ <in>git remote add ${GASERVER/.*/} ssh://${GAUSER}@git-annex-${GASSHHOSTNAME}:${GAPATH}</in> $ <in>git config remote.${GASERVER/.*/}.annex-ignore false</in>
After the 'ssh-copy-id stage
', the key can be used to get a full session. This needs to be limited on the server, by prepending the following to the newly added key in '.ssh/authorized_keys
', replacing 'GAPATH
' by the value of '$GAPATH
':
command="GIT_ANNEX_SHELL_DIRECTORY='GAPATH' ~/.ssh/git-annex-shell",no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-pty ssh-rsa...
In case the file get overwritten, but the keys are still there.
$ <in>for KEY in ~/.ssh/git-annex/*.pub; do export KEY=${KEY/.pub/} export GASSHHOSTNAME=${KEY/*git-annex-/} grep -q $GASSHHOSTNAME ~/.ssh/config && continue export GASERVER=`echo ${GASSHHOSTNAME} | sed 's/-[a-zA-Z0-9]\+_.*//'` export GAUSERPATH=${GASSHHOSTNAME/${GASERVER}-/} export GAUSER=${GAUSERPATH/_*/} export GAPATH=${GAUSERPATH/*_/} export GAPATH=${GAPATH//.2F//} cat << EOF >> ~/.ssh/config Host git-annex-$GASSHHOSTNAME Hostname $GASERVER IdentityFile ~/.ssh/git-annex/key.git-annex-$GASSHHOSTNAME IdentitiesOnly yes StrictHostKeyChecking yes EOF done</in>
[alias] ameta = annex metadata ametalist = !git annex metadata | sed -n 's/.*\\s\\([^\\s]\\+=.*\\)/\\1/p' | sort | uniq