# Repo with only one file

11 messages from 2013-08-07 to 2013-08-09. Participants: shawn wilson, Johannes Sixt, Phil Hord.
Thread: https://gitlist.dev/t/34630

## shawn wilson, 2013-08-07 06:24

Subject: Repo with only one file
Message-ID: <CAH_OBid8SO3ydpjhRHa68s+54CScLh=jactxTQhwQPo-jcnAvA@mail.gmail.com>
URL: https://gitlist.dev/e/CAH_OBid8SO3ydpjhRHa68s%2B54CScLh%3DjactxTQhwQPo-jcnAvA%40mail.gmail.com

```
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, 2013-08-07 10:43

Subject: Re: Repo with only one file
Message-ID: <520224E0.5060206@viscovery.net>
URL: https://gitlist.dev/e/520224E0.5060206%40viscovery.net
In-Reply-To: <CAH_OBid8SO3ydpjhRHa68s+54CScLh=jactxTQhwQPo-jcnAvA@mail.gmail.com>

```
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

-- Hannes

```

## shawn wilson, 2013-08-07 21:07

Subject: Re: Repo with only one file
Message-ID: <CAH_OBicysTTu9YdHsHz0H6x3umU5va68J3nT1qHA9-CJY9+E=A@mail.gmail.com>
URL: https://gitlist.dev/e/CAH_OBicysTTu9YdHsHz0H6x3umU5va68J3nT1qHA9-CJY9%2BE%3DA%40mail.gmail.com
In-Reply-To: <520224E0.5060206@viscovery.net>

```
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

```

## Phil Hord, 2013-08-08 21:11

Subject: Re: Repo with only one file
Message-ID: <CABURp0o_07HdB2o0knPABtAiiuHQ6-fYgemvdCYOsdSghO7v1w@mail.gmail.com>
URL: https://gitlist.dev/e/CABURp0o_07HdB2o0knPABtAiiuHQ6-fYgemvdCYOsdSghO7v1w%40mail.gmail.com
In-Reply-To: <CAH_OBicysTTu9YdHsHz0H6x3umU5va68J3nT1qHA9-CJY9+E=A@mail.gmail.com>

```
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

Phil

```

## Johannes Sixt, 2013-08-09 06:25

Subject: Re: Repo with only one file
Message-ID: <52048B5B.5060009@viscovery.net>
URL: https://gitlist.dev/e/52048B5B.5060009%40viscovery.net
In-Reply-To: <CABURp0o_07HdB2o0knPABtAiiuHQ6-fYgemvdCYOsdSghO7v1w@mail.gmail.com>

```
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
>>>>
>>>> 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, 2013-08-09 06:33

Subject: Re: Repo with only one file
Message-ID: <CAH_OBicF3xn8+MsKH0nTg-HnPg58T-TWHW20r7GqXOm3Nbutfg@mail.gmail.com>
URL: https://gitlist.dev/e/CAH_OBicF3xn8%2BMsKH0nTg-HnPg58T-TWHW20r7GqXOm3Nbutfg%40mail.gmail.com
In-Reply-To: <52048B5B.5060009@viscovery.net>

```
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).

```

## Johannes Sixt, 2013-08-09 06:50

Subject: Re: Repo with only one file
Message-ID: <52049121.2080604@viscovery.net>
URL: https://gitlist.dev/e/52049121.2080604%40viscovery.net
In-Reply-To: <CAH_OBicF3xn8+MsKH0nTg-HnPg58T-TWHW20r7GqXOm3Nbutfg@mail.gmail.com>

```
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

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

-- Hannes

```

## shawn wilson, 2013-08-09 10:03

Subject: Re: Repo with only one file
Message-ID: <CAH_OBifYFyVVo_OEfniWJE=0peX+UPLkRznqyQzvO4gGGLu_tQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAH_OBifYFyVVo_OEfniWJE%3D0peX%2BUPLkRznqyQzvO4gGGLu_tQ%40mail.gmail.com
In-Reply-To: <52049121.2080604@viscovery.net>

```
On Fri, Aug 9, 2013 at 2:50 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
> 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, 2013-08-09 10:32

Subject: Re: Repo with only one file
Message-ID: <5204C546.1030502@viscovery.net>
URL: https://gitlist.dev/e/5204C546.1030502%40viscovery.net
In-Reply-To: <CAH_OBifYFyVVo_OEfniWJE=0peX+UPLkRznqyQzvO4gGGLu_tQ@mail.gmail.com>

```
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

```

## Phil Hord, 2013-08-09 15:00

Subject: Re: Repo with only one file
Message-ID: <CABURp0p9NGoL=F8-xpicz5J+TmOopYhv-qmxoWagHOcBiKn6=w@mail.gmail.com>
URL: https://gitlist.dev/e/CABURp0p9NGoL%3DF8-xpicz5J%2BTmOopYhv-qmxoWagHOcBiKn6%3Dw%40mail.gmail.com
In-Reply-To: <CAH_OBifYFyVVo_OEfniWJE=0peX+UPLkRznqyQzvO4gGGLu_tQ@mail.gmail.com>

```
On Fri, Aug 9, 2013 at 6:03 AM, shawn wilson <ag4ve.us@gmail.com> wrote:
> 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

```

## shawn wilson, 2013-08-09 21:54

Subject: Re: Repo with only one file
Message-ID: <CAH_OBievQ72gid7OQwCwij3ApjStFScGSQsV_w2Oap24GsHobg@mail.gmail.com>
URL: https://gitlist.dev/e/CAH_OBievQ72gid7OQwCwij3ApjStFScGSQsV_w2Oap24GsHobg%40mail.gmail.com
In-Reply-To: <5204C546.1030502@viscovery.net>

```
On Fri, Aug 9, 2013 at 6:32 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
> 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?

```
