Skip to content

Instantly share code, notes, and snippets.

@alkavan
Last active December 17, 2015 05:39
Show Gist options
  • Save alkavan/5559287 to your computer and use it in GitHub Desktop.
Save alkavan/5559287 to your computer and use it in GitHub Desktop.
List of useful GIT commands.

Clean staging area

Remove all deleted files from staging area

git diff --diff-filter=D --name-only -z | xargs -0 git rm

SVN import/export

Read svn author

svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > ~/svn-project-authors-transform.txt

Import svn repository

git svn clone svn://svn.youdomain.com/<repo> -s --no-metadata -A ~/svn-project-authors-transform.txt -t tags -b branches -T trunk project.git

Export branch to new repository

git clone <repository-url>
cd <repository-directory>
checkout <branch-name>
git remote rm origin
git filter-branch -- --all
git remote add origin <new-repository-url>
git push -u origin <branch-name>

With sub directory filter

git filter-branch --subdirectory-filter <directory-1> -- --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment