home | list info | list archive | date index | thread index

[OCLUG-Tech] a couple questions on "git filter-branch", if i may

  • Subject: [OCLUG-Tech] a couple questions on "git filter-branch", if i may
  • From: "Robert P. J. Day" <rpjday [ at ] crashcourse [ dot ] ca>
  • Date: Wed, 6 Sep 2017 09:30:45 -0400 (EDT)
  having never used "git filter-branch" in any meaningful way, a
couple questions about some situations that don't seem to be explained
in the docs very well.

  so, the standard example everyone uses is to go back through a git
repo and remove something completely from the history. let's say it
was the top-level /README file:

  $ git filter-branch --tree-filter "rm /README" @

and i guess i could add the "--prune-empty" option that will take out
the commit that added that file in the first place (if such a commit
existed). any comments on that trivial example?

  now let's make it more complicated. say i added that file to the
repo early on, it was there for a while, then i "git rm"ed it because
it was garbage, and some time later, i re-introduced that /README file
(possibly with different content, possibly not). i might still want to
restructure my repo to look like that *earlier* version of the
/README file never existed, but i suspect i can't just do this
anymore:

  $ git filter-branch --tree-filter "rm /README" @

if i read the docs correctly, this will remove *all* incarnations of
that top-level file from the history, is that correct?

  at that point, it seems like i would use some form of:

  $ git filter-branch --commit-filter '...'

where my commit filter would reflect the single commit that added that
earlier version of the file, and nothing more. does that sound
reasonable?

  i will now continue poring over the docs, and if anyone wants to
provide a link to a really good tutorial on git filter-branch apart
from the standard docs, feel free.

rday

-- 

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================