Delete file history from only one branch, not the whole repo

I have a topic thread (off master ) that has a lot of changes. Throughout the history of this thread, there have been many changes to a specific file. How to delete all changes to this file during the history of my thread branch?

Additional notes:

  • Note that the file existed before the topic thread was created. I do not want to delete the file as such.
  • I have several solutions, but so far they seem tedious. I will send them as separate responses.
  • Can git filter-branch be used for this?
  • My topic thread contains about ... say ... 60 commits.
+4
source share
3 answers

Using git filter-branch :

 $ git checkout topic-branch $ git filter-branch --index-filter 'git checkout master -- myfile' master..HEAD 
+3
source

Restore the tree against the beginning of the branch. Use the attributes to define a different merge strategy for this particular file, in particular "merge.ours" (always keep our file). This article explains how to: tell git to use our merge strategy for specific files (the question itself tells you how to do this, the answer is just the question of what the questionnaire was).

I donโ€™t know how โ€œtiringโ€ this is, for example, whether you need to confirm something with every commit, because I didnโ€™t do it. But I would not have thought.

0
source

Do an interactive reboot. A decent version would be to simply edit / change each commit, deleting the change:

 git checkout topic-branch git rebase -i master # set all commits to edit # for every commit; do git show --stat # if myfile is not changes: git rebase --continue # copy the commit message git reset HEAD^ git reset myfile git checkout myfile git commit # paste in commit message git rebase --continue # ...until we are done 

A slightly improved version is to use git log master.. myfile and edit only registered commits.

0
source

All Articles