Skip to content

Instantly share code, notes, and snippets.

@Trass3r
Last active November 28, 2017 14:16
Show Gist options
  • Save Trass3r/57638e29f19897cdc352 to your computer and use it in GitHub Desktop.
Save Trass3r/57638e29f19897cdc352 to your computer and use it in GitHub Desktop.
git magic
# merge into subdir
git config --global mergeintosubdirectory "!sh -c 'git merge -s ours --no-commit $1 && git read-tree --prefix=$2 -u $1 && git status' -"
# fix line endings
# use RAM disk since this is slow
# added benefit of creating .gitattributes in the first commit
FASTDISKWORKDIR=$TEMP/workdir
time git filter-branch -d "$FASTDISKWORKDIR" -f --tree-filter "echo '* text=auto' > .gitattributes && rm $FASTDISKWORKDIR/index && git reset && git add -u" --tag-name-filter cat --prune-empty -- --all
# rewrites with commands other than filter-branch alter the committers
fixcommitdates = filter-branch --env-filter 'export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"'
# GC run
git reflog expire --expire=now --all
git gc --prune=now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment