0

At most, A file in git repository has history that includes many commits. Now, I want to extract file[s] with all history that can trace from HEAD(with same AuthorDate/CommitDate), and want to write out to new empty branch(able to create with git checkout --orphan).

I know that git filter-branch has potential to do that, however, I don't know how because it is too powerful for me.

yumetodo
  • 1,147
  • 7
  • 19

1 Answers1

0

I think you can just branch off of the old branch and remove excessive files in that new branch using git filter-branch. After removing unnecessary files in the new branch you'll have two branches — the old branch untouched and the new branch with the files that you want. The history in the new branch will be preserved (actually, recreated) by git filter-branch.

phd
  • 82,685
  • 13
  • 120
  • 165
  • How to specify files that want to remove on `git filter-branch`? – yumetodo Jun 17 '17 at 15:53
  • `git filter-branch --index-filter 'git rm --cached --ignore-unmatch file1 file2…'`. See https://stackoverflow.com/q/872565/7976758, https://stackoverflow.com/q/17993505/7976758, https://stackoverflow.com/search?q=git+filter-branch+remove+files – phd Jun 17 '17 at 18:30
  • Thank you! I used BFG Repo-Cleaner and followed your approach. After that, I use git rebase to remove empty commit caused by BFG Repo-Cleaner. – yumetodo Jun 18 '17 at 08:43