git splitting repository by subfolder and retain all old branches

Short answer git filter-branch offers exactly the functionality you want. With the –subdirectory-filter option you can create a new set of commits where the contents of subDirectory are at the root of the directory. git filter-branch –prune-empty –subdirectory-filter subDirectory — –branches Walkthrough The following is an example to perform this in a safe way. You … Read more

Git: split pull request into smaller PR’s based upon the new directories in the pull request

is there a way to pull files out of a branch including their commit history into a new branch? You pull a commit, meaning a whole repo into a branch, not just some files. One good option would then be to reset the files you don’t want to their content pre-branch –x–x–x (master) \ y–y–y … Read more

Update a development team with rewritten Git repo history, removing big files

Yes, your solution will work. You also have another option: instead of doing this on the central repo, run the filter on your clone and then push it back with git push –force –all. This will force the server to accept the new branches from your repository. This replaces step 2 only; the other steps … Read more

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

How do I change the author and committer name/email for multiple commits?

NOTE: This answer changes SHA1s, so take care when using it on a branch that has already been pushed. If you only want to fix the spelling of a name or update an old email, Git lets you do this without rewriting history using .mailmap. See my other answer. Using Rebase First, if you haven’t … 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

How to move a file from one git repository to another while preserving history

This worked for me, but with a whole directory. As shown here ~$ cd neu ~/neu$ git filter-branch –subdirectory-filter FooBar HEAD ~/neu$ git reset –hard ~/neu$ git remote rm origin ~/neu$ rm -r .git/refs/original/ ~/neu$ git reflog expire –expire=now –all ~/neu$ git gc –aggressive ~/neu$ git prune ~/neu$ git remote add origin git://github.com/FooBar/neu.git EDIT: For … 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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)