Skip to content

Instantly share code, notes, and snippets.

@jikuja
Created October 13, 2020 17:34
Show Gist options
  • Save jikuja/516b102c8faf92f882dc8ce6dc486cdb to your computer and use it in GitHub Desktop.
Save jikuja/516b102c8faf92f882dc8ce6dc486cdb to your computer and use it in GitHub Desktop.
Git cleanup

Git repository cleanup

After adding .gitignore file, commands git ls-files -z --ignored --exclude-standard | xargs -0 git rm --cached and git commit -m "Repository cleanup adter adding .gitignore" can be used to delete all committed files from git.

Deleted file recovery

Command git log --all --pretty=format: --name-only --diff-filter=D -E $COMMIT -- *.user lists all deleted .user files in given commit.

Deleted files can be recovered from given commit into workspace with git log --all --pretty=format: --name-only --diff-filter=D -E -z $COMMIT -- *.user | xargs -0 git restore --source=$COMMIT^ -W -- where COMMIT is commit that deleted files.

Running the command recovers files into working directory. *.user is example here and can be replaces with given set of files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment