How do I run a code formatter over my source without modifying git history?

You can make git blame ignoring certain commits, which do only mass reformatting etc.: Create a file .git-blame-ignore-revs like: # Format commit 1 SHA: 1234af5….. # Format commit 2 SHA: 2e4ac56….. Then do git config blame.ignoreRevsFile .git-blame-ignore-revs , so that you don’t have to use the –ignore-revs-file option every time with git blame. Upvote https://github.com/github/feedback/discussions/5033 … Read more

Split large Git repository into many smaller ones

This will setup MyABRepo; you can do My12Repo similarly of course. git clone MyHugeRepo/ MyABRepo.tmp/ cd MyABRepo.tmp git filter-branch –prune-empty –index-filter ‘git rm –cached –ignore-unmatch DIR_1/* DIR_2/*’ HEAD A reference to .git/refs/original/refs/heads/master remains. You can remove that up with: cd .. git clone MyABRepo.tmp MyABRepo If all went well you can then remove MyABRepo.tmp. If … Read more

Splitting a set of files within a git repo into their own repository, preserving relevant history [duplicate]

Just to close the loop on this so it appears as answered. By using index-filter or tree-filter and then applying reverse logic like git ls-tree piped into (multiple) grep -v‘s piped into xargs for git rm you can indeed remove everything that doesn’t match a narrow set of file names/directories. Here is the command I … Read more

Detach many subdirectories into a new, separate Git repository

Instead of having to deal with a subshell and using ext glob (as kynan suggested), try this much simpler approach: git filter-branch –index-filter ‘git rm –cached -qr –ignore-unmatch — . && git reset -q $GIT_COMMIT — apps/AAA libs/XXX’ –prune-empty — –all As mentioned by void.pointer’s comment, this will remove everything except apps/AAA and libs/XXX from … Read more

Completely remove files from Git repo and remote on GitHub

This is what you’re looking for: ignoring doesn’t remove a file. I suggest you read that page, but here’s the specific command to use: git filter-branch –index-filter \ ‘git rm -r –cached –ignore-unmatch <file/dir>’ HEAD Also, to remove all the deleted files from caches git creates, use: rm -rf .git/refs/original/ && \ git reflog expire … Read more

How to substitute text from files in git history?

I’d recommend using the BFG Repo-Cleaner, a simpler, faster alternative to git-filter-branch specifically designed for rewriting files from Git history. You should carefully follow these steps here: https://rtyley.github.io/bfg-repo-cleaner/#usage – but the core bit is just this: download the BFG’s jar (requires Java 7 or above) and run this command: $ java -jar bfg.jar –replace-text replacements.txt … Read more