* removing files from history but not filesystem
@ 2011-06-28 6:13 Shantanu Pavgi
2011-06-28 7:04 ` Christof Krüger
0 siblings, 1 reply; 6+ messages in thread
From: Shantanu Pavgi @ 2011-06-28 6:13 UTC (permalink / raw)
To: git@vger.kernel.org
Hi,
How do I delete files from commit history, but still keep these files untracked on the filesystem?
I tried 'git rm --cached' command using 'git filter-branch'; however it deleted file from the filesystem as well.
{{{
$ git filter-branch --index-filter 'git rm --cached --ignore-unmatch */one.txt' HEAD
}}}
I am guessing since file is getting deleted from commit history (where it was created/modified), it won't be present on the filesystem as well. Am I following it correctly? Any further elaboration on this problem will be really helpful.
Do I need to move concerned files to some other temporary location and rename them back to original filename? I have tried following commands with tree-filter, but it is failing as of now (second mv command needs to know correct filesystem path which was matched for */one.txt):
{{{
$ git filter-branch -f --tree-filter \
> 'if [ -f */one.txt ]; then mv */one.txt */one.txt.keep; fi; rm -f */one.txt; if [ -f */one.txt.keep ]; then mv -f */one.txt.keep */one.txt; fi' \
> HEAD
}}}
Any help?
--
Thanks,
Shantanu.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: removing files from history but not filesystem
2011-06-28 6:13 removing files from history but not filesystem Shantanu Pavgi
@ 2011-06-28 7:04 ` Christof Krüger
2011-06-29 4:10 ` Shantanu Pavgi
0 siblings, 1 reply; 6+ messages in thread
From: Christof Krüger @ 2011-06-28 7:04 UTC (permalink / raw)
To: Shantanu Pavgi; +Cc: git@vger.kernel.org
Hi,
> $ git filter-branch --index-filter 'git rm --cached --ignore-unmatch
> */one.txt' HEAD
The following should work:
git branch temp
git filter-branch --index-filter 'git rm --cached --ignore-unmatch foo' temp
git reset temp
This creates branch "temp" pointing to the same commit as "master".
Then you filter-branch the "temp" branch. This leaves file "foo" in your
working directory intact, as your current branch is actually "master". The
third step resets your current "branch" to the commit pointed by the
rewritten branch "temp". The default for git reset is --mixed which
according to the man page leaves the working tree alone.
Regards,
Chris
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: removing files from history but not filesystem
2011-06-28 7:04 ` Christof Krüger
@ 2011-06-29 4:10 ` Shantanu Pavgi
2011-06-29 6:08 ` Christof Krüger
0 siblings, 1 reply; 6+ messages in thread
From: Shantanu Pavgi @ 2011-06-29 4:10 UTC (permalink / raw)
To: Christof Krüger; +Cc: git@vger.kernel.org
On Jun 28, 2011, at 2:04 AM, Christof Krüger wrote:
> Hi,
>
>> $ git filter-branch --index-filter 'git rm --cached --ignore-unmatch
>> */one.txt' HEAD
>
> The following should work:
>
> git branch temp
> git filter-branch --index-filter 'git rm --cached --ignore-unmatch foo' temp
> git reset temp
>
> This creates branch "temp" pointing to the same commit as "master".
> Then you filter-branch the "temp" branch. This leaves file "foo" in your
> working directory intact, as your current branch is actually "master". The
> third step resets your current "branch" to the commit pointed by the
> rewritten branch "temp". The default for git reset is --mixed which
> according to the man page leaves the working tree alone.
>
Thanks for the reply Chris. It worked for me. I am not following last command "git reset <branch-name>" though. I have used SHA1 commit object names in 'git reset' command, but I am not sure how <commit> is using branch name here. Is it because branch is a commit pointer in the git history?
Also, how do I specify rev-list HEAD-1 so that 'git rm' will be run on all commits excepts latest commit? Following didn't work for me, so I guess I am not following syntax here.
{{{
$ git filter-branch --index-filter 'git rm --cached --ignore-unmatch apple' HEAD~1
Which ref do you want to rewrite?
}}}
Any help?
--
Thanks,
Shantanu.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: removing files from history but not filesystem
2011-06-29 4:10 ` Shantanu Pavgi
@ 2011-06-29 6:08 ` Christof Krüger
2011-06-29 16:57 ` Christof Krüger
2011-06-29 21:45 ` Shantanu Pavgi
0 siblings, 2 replies; 6+ messages in thread
From: Christof Krüger @ 2011-06-29 6:08 UTC (permalink / raw)
To: Shantanu Pavgi; +Cc: git@vger.kernel.org
Hi
> Thanks for the reply Chris. It worked for me. I am not following last
> command "git reset <branch-name>" though. I have used SHA1 commit
> object names in 'git reset' command, but I am not sure how <commit> is
> using branch name here. Is it because branch is a commit pointer in
> the git history?
While being on the master branch, issuing "git reset temp" tells git to
"let the master branch point to wherever the symbolic reference temp
points now".
You did something very similar with git filter-branch already. There you
specified HEAD~1, which is the same as telling git to dereference the
symbolic ref "HEAD" and take its first parent. I don't know any place
where git wouldn't accept symbolic references instead of raw sha1 sums.
> Also, how do I specify rev-list HEAD-1 so that 'git rm' will be run on
> all commits excepts latest commit? Following didn't work for me, so I
> guess I am not following syntax here.
> {{{ $ git filter-branch
> --index-filter 'git rm --cached --ignore-unmatch apple' HEAD~1
> Which ref do you want to rewrite?
> }}}
git filter-branch expects a symbolic reference within the rev-list. It
would be pointless to filter the commits without a symbolic reference
being bent over to point to the rewritten branch once done.
What you can do is the following:
git filter-branch --index-filter 'test $GIT_COMMIT =
35644cb5fa34e033593f6f0d27c332443b6867d8 || git rm --cached
--ignore-unmatch foo' HEAD
If "test $GIT_COMMIT = <sha1>" is true, the following git rm command
won't be executed for that commit.
Choose the hash to be the one you want to skip (HEAD).
Another possible way would be to create a temporary branch to point at
HEAD^, filter-branch it, then add a graft to stitch the remaining commit
on top of it, then filter-branch HEAD and then remove the branch. But
this is a bit advanced for the case where you just want to omit one
commit.
Regards,
Chris
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: removing files from history but not filesystem
2011-06-29 6:08 ` Christof Krüger
@ 2011-06-29 16:57 ` Christof Krüger
2011-06-29 21:45 ` Shantanu Pavgi
1 sibling, 0 replies; 6+ messages in thread
From: Christof Krüger @ 2011-06-29 16:57 UTC (permalink / raw)
To: Shantanu Pavgi; +Cc: git@vger.kernel.org
> Another possible way would be to create a temporary branch to point at
> HEAD^, filter-branch it, then add a graft to stitch the remaining commit
> on top of it, then filter-branch HEAD and then remove the branch. But
> this is a bit advanced for the case where you just want to omit one
> commit.
That should have been "[...] and then remove the _graft_." (and the
temporary branch).
Regards,
Chris
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: removing files from history but not filesystem
2011-06-29 6:08 ` Christof Krüger
2011-06-29 16:57 ` Christof Krüger
@ 2011-06-29 21:45 ` Shantanu Pavgi
1 sibling, 0 replies; 6+ messages in thread
From: Shantanu Pavgi @ 2011-06-29 21:45 UTC (permalink / raw)
To: Christof Krüger; +Cc: git@vger.kernel.org
On Jun 29, 2011, at 1:08 AM, Christof Krüger wrote:
> Hi
>
>> Thanks for the reply Chris. It worked for me. I am not following last
>> command "git reset <branch-name>" though. I have used SHA1 commit
>> object names in 'git reset' command, but I am not sure how <commit> is
>> using branch name here. Is it because branch is a commit pointer in
>> the git history?
> While being on the master branch, issuing "git reset temp" tells git to
> "let the master branch point to wherever the symbolic reference temp
> points now".
> You did something very similar with git filter-branch already. There you
> specified HEAD~1, which is the same as telling git to dereference the
> symbolic ref "HEAD" and take its first parent. I don't know any place
> where git wouldn't accept symbolic references instead of raw sha1 sums.
>
>> Also, how do I specify rev-list HEAD-1 so that 'git rm' will be run on
>> all commits excepts latest commit? Following didn't work for me, so I
>> guess I am not following syntax here.
>> {{{ $ git filter-branch
>> --index-filter 'git rm --cached --ignore-unmatch apple' HEAD~1
>> Which ref do you want to rewrite?
>> }}}
> git filter-branch expects a symbolic reference within the rev-list. It
> would be pointless to filter the commits without a symbolic reference
> being bent over to point to the rewritten branch once done.
>
> What you can do is the following:
>
> git filter-branch --index-filter 'test $GIT_COMMIT =
> 35644cb5fa34e033593f6f0d27c332443b6867d8 || git rm --cached
> --ignore-unmatch foo' HEAD
>
> If "test $GIT_COMMIT = <sha1>" is true, the following git rm command
> won't be executed for that commit.
> Choose the hash to be the one you want to skip (HEAD).
>
> Another possible way would be to create a temporary branch to point at
> HEAD^, filter-branch it, then add a graft to stitch the remaining commit
> on top of it, then filter-branch HEAD and then remove the branch. But
> this is a bit advanced for the case where you just want to omit one
> commit.
>
> Regards,
> Chris
>
> --
Thanks for explaining it in detail Chris. That's really helpful.
--
Shantanu.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-06-29 21:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-28 6:13 removing files from history but not filesystem Shantanu Pavgi
2011-06-28 7:04 ` Christof Krüger
2011-06-29 4:10 ` Shantanu Pavgi
2011-06-29 6:08 ` Christof Krüger
2011-06-29 16:57 ` Christof Krüger
2011-06-29 21:45 ` Shantanu Pavgi
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).