From: "Robert P. J. Day" <rpjday@crashcourse.ca>
To: Git Mailing list <git@vger.kernel.org>
Subject: how to remove from history just *one* version of a file/dir?
Date: Thu, 14 Sep 2017 07:32:11 -0400 (EDT) [thread overview]
Message-ID: <alpine.LFD.2.21.1709140721130.19770@localhost.localdomain> (raw)
[is this the right place to ask questions about git usage? or is
there a different forum where one can submit possibly embarrassingly
silly questions?]
i've been perusing "git filter-branch", and i'm curious if i have
the right idea about how to very selectively get rid of some useless
history.
say, early on, one commits a sizable directory of content, call it
/mydir. that directory sits there for a while until it becomes obvious
it's out of date and worthless and should never have been committed.
the obvious solution would seem to be:
$ git filter-branch --tree-filter 'rm -rf /mydir' HEAD
correct?
however, say one version of that directory was committed early on,
then later tossed for being useless with "git rm", and subsequently
replaced by newer content under exactly the same name. now i'd like to
go back and delete the history related to that early version of
/mydir, but not the second.
obviously, i can't use the above command as it would delete both
versions. so it appears the solution would be a trivial application of
the "--commit-filter" option:
git filter-branch --commit-filter '
if [ "$GIT_COMMIT" = "<commit-id>" ] ; then
skip_commit "$@";
else
git commit-tree "$@";
fi' HEAD
where <commit-id> is the commit that introduced the first verrsion of
/mydir. do i have that right? is there a simpler way to do this?
rday
--
========================================================================
Robert P. J. Day Ottawa, Ontario, CANADA
http://crashcourse.ca
Twitter: http://twitter.com/rpjday
LinkedIn: http://ca.linkedin.com/in/rpjday
========================================================================
next reply other threads:[~2017-09-14 11:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-14 11:32 Robert P. J. Day [this message]
2017-09-14 12:23 ` how to remove from history just *one* version of a file/dir? Jeff King
2017-09-15 11:06 ` Robert P. J. Day
2017-09-15 11:35 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LFD.2.21.1709140721130.19770@localhost.localdomain \
--to=rpjday@crashcourse.ca \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).