threads / discuss / 34630

Repo with only one file

Subject: Repo with only one file

## tl;dr

11 messages between Aug 7, 2013 and Aug 9, 2013.

replies: 10people: 3as markdown or json

shawn wilson· Aug 7, 2013, 06:24 UTC · lore

I started writing this script in a repo I have called misc-scripts where I just keep one off projects and the like (notes, throw away scripts, etc). Well, my boss asked me to create a repo for one of these scripts and I'd like to keep the commit history.

Ok, so: % find -type f ! -iname "webban.pl" | while read f; do git filter-branch -f --index-filter "git rm --cached --ignore-unmatch $f" HEAD ; done

Which basically did it. But, I've got this one commit that seems to be orphaned - it doesn't change any files. That is, it shows up in a git log but not a git whatchanged. When I try to rebase -p --onto, I get tons of conflicts, git adding blah in every other line of the file and after I totally mess up the repo, that commit is still there. If I do a git checkout and try to amend the message, I get:

# Not currently on any branch. # # Initial commit # # No changes You asked to amend the most recent commit, but doing so would make it empty. You can repeat your command with --allow-empty, or you can remove the commit entirely with "git reset HEAD^".

iWhen I do --allow-empty, I can no longer see any other commits.

So, how do I remove this commit or what is the proper way to get this one file into a repo with nothing else?

Also, I sign my commits and would like to keep each commit signed if at all possible.

Johannes Sixt· Aug 7, 2013, 10:43 UTC · re: shawn wilson · lore

Re: Repo with only one file

Am 8/7/2013 8:24, schrieb shawn wilson:> ... create a repo for one of
Show 9 quoted lines
> these scripts and I'd like to keep the commit history.
>
> Ok, so:
> % find -type f ! -iname "webban.pl" | while read f; do git
> filter-branch -f --index-filter "git rm --cached --ignore-unmatch $f"
> HEAD ; done
>
> Which basically did it. But, I've got this one commit that seems to be
> orphaned - it doesn't change any files.
Try this:
  git filter-branch HEAD -- webban.pl
-- Hannes
shawn wilson· Aug 7, 2013, 21:07 UTC · re: Johannes Sixt · lore

Re: Repo with only one file

On Wed, Aug 7, 2013 at 6:43 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
Show 15 quoted lines
> Am 8/7/2013 8:24, schrieb shawn wilson:> ... create a repo for one of
>> these scripts and I'd like to keep the commit history.
>>
>> Ok, so:
>> % find -type f ! -iname "webban.pl" | while read f; do git
>> filter-branch -f --index-filter "git rm --cached --ignore-unmatch $f"
>> HEAD ; done
>>
>> Which basically did it. But, I've got this one commit that seems to be
>> orphaned - it doesn't change any files.
>
> Try this:
>
>   git filter-branch HEAD -- webban.pl
>
 % git filter-branch HEAD -- webban.pl
Cannot create a new backup.
A previous backup already exists in refs/original/
Force overwriting the backup with -f
 % git filter-branch -f HEAD -- webban.pl
Rewrite 1e04b18c256c996312f167be808733bcc755f1e3 (9/9)
WARNING: Ref 'refs/heads/master' is unchanged
Phil Hord· Aug 8, 2013, 21:11 UTC · re: shawn wilson · lore

Re: Repo with only one file

On Wed, Aug 7, 2013 at 5:07 PM, shawn wilson <ag4ve.us@gmail.com> wrote:
Show 24 quoted lines
> On Wed, Aug 7, 2013 at 6:43 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
>> Am 8/7/2013 8:24, schrieb shawn wilson:> ... create a repo for one of
>>> these scripts and I'd like to keep the commit history.
>>>
>>> Ok, so:
>>> % find -type f ! -iname "webban.pl" | while read f; do git
>>> filter-branch -f --index-filter "git rm --cached --ignore-unmatch $f"
>>> HEAD ; done
>>>
>>> Which basically did it. But, I've got this one commit that seems to be
>>> orphaned - it doesn't change any files.
>>
>> Try this:
>>
>>   git filter-branch HEAD -- webban.pl
>>
>
>  % git filter-branch HEAD -- webban.pl
> Cannot create a new backup.
> A previous backup already exists in refs/original/
> Force overwriting the backup with -f
>  % git filter-branch -f HEAD -- webban.pl
> Rewrite 1e04b18c256c996312f167be808733bcc755f1e3 (9/9)
> WARNING: Ref 'refs/heads/master' is unchanged

I think you can ignore the warning. Maybe you want to create a new branch which only has this file in it now.

   $ git checkout -b webban
Phil
Johannes Sixt· Aug 9, 2013, 06:25 UTC · re: Phil Hord · lore

Re: Repo with only one file

Am 8/8/2013 23:11, schrieb Phil Hord:
Show 30 quoted lines
> On Wed, Aug 7, 2013 at 5:07 PM, shawn wilson <ag4ve.us@gmail.com> wrote:
>> On Wed, Aug 7, 2013 at 6:43 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
>>> Am 8/7/2013 8:24, schrieb shawn wilson:> ... create a repo for one of
>>>> these scripts and I'd like to keep the commit history.
>>>>
>>>> Ok, so:
>>>> % find -type f ! -iname "webban.pl" | while read f; do git
>>>> filter-branch -f --index-filter "git rm --cached --ignore-unmatch $f"
>>>> HEAD ; done
>>>>
>>>> Which basically did it. But, I've got this one commit that seems to be
>>>> orphaned - it doesn't change any files.
>>>
>>> Try this:
>>>
>>>   git filter-branch HEAD -- webban.pl
>>>
>>
>>  % git filter-branch HEAD -- webban.pl
>> Cannot create a new backup.
>> A previous backup already exists in refs/original/
>> Force overwriting the backup with -f
>>  % git filter-branch -f HEAD -- webban.pl
>> Rewrite 1e04b18c256c996312f167be808733bcc755f1e3 (9/9)
>> WARNING: Ref 'refs/heads/master' is unchanged
> 
> I think you can ignore the warning.  Maybe you want to create a new
> branch which only has this file in it now.
> 
>    $ git checkout -b webban

I'm not sure. On second thought, my suggested command is not sufficient. It does remove the empty commits, but it does not remove the other files. So, Shawn's original filter-branch invocations are still needed.

-- Hannes
shawn wilson· Aug 9, 2013, 06:33 UTC · re: Johannes Sixt · lore

Re: Repo with only one file

On Fri, Aug 9, 2013 at 2:25 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
Show 11 quoted lines
> Am 8/8/2013 23:11, schrieb Phil Hord:
>> On Wed, Aug 7, 2013 at 5:07 PM, shawn wilson <ag4ve.us@gmail.com> wrote:
>>> On Wed, Aug 7, 2013 at 6:43 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
>>>> Am 8/7/2013 8:24, schrieb shawn wilson:> ... create a repo for one of
>>>>> these scripts and I'd like to keep the commit history.
>>>>>
>>>>> Ok, so:
>>>>> % find -type f ! -iname "webban.pl" | while read f; do git
>>>>> filter-branch -f --index-filter "git rm --cached --ignore-unmatch $f"
>>>>> HEAD ; done
>>>>>
> I'm not sure. On second thought, my suggested command is not sufficient.
> It does remove the empty commits, but it does not remove the other files.
> So, Shawn's original filter-branch invocations are still needed.
>

Yeah, I have tried this and haven't gotten any closer. I can either remove all of the history or that one commit that has nothing to do with my file is there. This is also reproducable in a new repo.

Is this a bug with filter-branch or git? This doesn't seem like a feature (or how things should act).

Johannes Sixt· Aug 9, 2013, 06:50 UTC · re: shawn wilson · lore

Re: Repo with only one file

Am 8/9/2013 8:33, schrieb shawn wilson:
Show 24 quoted lines
> On Fri, Aug 9, 2013 at 2:25 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
>> Am 8/8/2013 23:11, schrieb Phil Hord:
>>> On Wed, Aug 7, 2013 at 5:07 PM, shawn wilson <ag4ve.us@gmail.com> wrote:
>>>> On Wed, Aug 7, 2013 at 6:43 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
>>>>> Am 8/7/2013 8:24, schrieb shawn wilson:> ... create a repo for one of
>>>>>> these scripts and I'd like to keep the commit history.
>>>>>>
>>>>>> Ok, so:
>>>>>> % find -type f ! -iname "webban.pl" | while read f; do git
>>>>>> filter-branch -f --index-filter "git rm --cached --ignore-unmatch $f"
>>>>>> HEAD ; done
>>>>>>
> 
>> I'm not sure. On second thought, my suggested command is not sufficient.
>> It does remove the empty commits, but it does not remove the other files.
>> So, Shawn's original filter-branch invocations are still needed.
>>
> 
> Yeah, I have tried this and haven't gotten any closer. I can either
> remove all of the history or that one commit that has nothing to do
> with my file is there. This is also reproducable in a new repo.
> 
> Is this a bug with filter-branch or git? This doesn't seem like a
> feature (or how things should act).

Let's check: After running your command above to remove other files, does the command

   git filter-branch -f HEAD webban.pl

remove the empty commit (if necessary, replace HEAD by the branch name that you are interested in)?

-- Hannes
shawn wilson· Aug 9, 2013, 10:03 UTC · re: Johannes Sixt · lore

Re: Repo with only one file

On Fri, Aug 9, 2013 at 2:50 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
Show 31 quoted lines
> Am 8/9/2013 8:33, schrieb shawn wilson:
>> On Fri, Aug 9, 2013 at 2:25 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
>>> Am 8/8/2013 23:11, schrieb Phil Hord:
>>>> On Wed, Aug 7, 2013 at 5:07 PM, shawn wilson <ag4ve.us@gmail.com> wrote:
>>>>> On Wed, Aug 7, 2013 at 6:43 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
>>>>>> Am 8/7/2013 8:24, schrieb shawn wilson:> ... create a repo for one of
>>>>>>> these scripts and I'd like to keep the commit history.
>>>>>>>
>>>>>>> Ok, so:
>>>>>>> % find -type f ! -iname "webban.pl" | while read f; do git
>>>>>>> filter-branch -f --index-filter "git rm --cached --ignore-unmatch $f"
>>>>>>> HEAD ; done
>>>>>>>
>>
>>> I'm not sure. On second thought, my suggested command is not sufficient.
>>> It does remove the empty commits, but it does not remove the other files.
>>> So, Shawn's original filter-branch invocations are still needed.
>>>
>>
>> Yeah, I have tried this and haven't gotten any closer. I can either
>> remove all of the history or that one commit that has nothing to do
>> with my file is there. This is also reproducable in a new repo.
>>
>> Is this a bug with filter-branch or git? This doesn't seem like a
>> feature (or how things should act).
>
> Let's check: After running your command above to remove other files, does
> the command
>
>    git filter-branch -f HEAD webban.pl
>

Ahha, no but: git filter-branch -f HEAD -- webban.pl did

Thanks.
The question still stands though - why is that unassociated commit left there?
Johannes Sixt· Aug 9, 2013, 10:32 UTC · re: shawn wilson · lore

Re: Repo with only one file

Am 8/9/2013 12:03, schrieb shawn wilson:
> The question still stands though - why is that unassociated commit left there?

Because your command did not remove it. filter-branch does not know that it is "unassociated" when you ask it to follow all commits beginning at HEAD. But when you say 'HEAD -- webban.pl', you ask it to follow only commits that touch webban.pl, which automatically skips that commit.

-- Hannes
shawn wilson· Aug 9, 2013, 21:54 UTC · re: Johannes Sixt · lore

Re: Repo with only one file

On Fri, Aug 9, 2013 at 6:32 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
Show 8 quoted lines
> Am 8/9/2013 12:03, schrieb shawn wilson:
>> The question still stands though - why is that unassociated commit left there?
>
> Because your command did not remove it. filter-branch does not know that
> it is "unassociated" when you ask it to follow all commits beginning at
> HEAD. But when you say 'HEAD -- webban.pl', you ask it to follow only
> commits that touch webban.pl, which automatically skips that commit.
>
I can go with that. However, I don't think that's the end of the story either:
 % du -sh .
192M    .
Something has been left behind. What? Or how do I figure that out and remove it?
Phil Hord· Aug 9, 2013, 15:00 UTC · re: shawn wilson · lore

Re: Repo with only one file

On Fri, Aug 9, 2013 at 6:03 AM, shawn wilson <ag4ve.us@gmail.com> wrote:
Show 14 quoted lines
> On Fri, Aug 9, 2013 at 2:50 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
>> Let's check: After running your command above to remove other files, does
>> the command
>>
>>    git filter-branch -f HEAD webban.pl
>>
>
> Ahha, no but:
> git filter-branch -f HEAD -- webban.pl
> did
>
> Thanks.
>
> The question still stands though - why is that unassociated commit left there?
Maybe you need  --prune-empty.
Phil

← back to recent threads