# How does Git know which files no longer needed during upgrade?

5 messages from 2009-03-03 to 2009-03-04. Participants: dealmaker, Miklos Vajna, Jeff King, Stefan Näwe.
Thread: https://gitlist.dev/t/18123

## dealmaker, 2009-03-03 21:51

Subject: How does Git know which files no longer needed during upgrade?
Message-ID: <22318714.post@talk.nabble.com>
URL: https://gitlist.dev/e/22318714.post%40talk.nabble.com

```

Hi,
  I am going to upgrade software to a newer version in my main trunk, I
decide to download the newer version and checkout the main trunk and  copy
it over to my main trunk.  If the older version has some files that are no
longer in the newer version, how does git determine whether to keep those
files or not?  Does it even notify me that those files are no longer needed?
Thanks.
-- 
View this message in context: http://www.nabble.com/How-does-Git-know-which-files-no-longer-needed-during-upgrade--tp22318714p22318714.html
Sent from the git mailing list archive at Nabble.com.

```

## Miklos Vajna, 2009-03-03 23:30

Subject: Re: How does Git know which files no longer needed during upgrade?
Message-ID: <20090303233058.GE4371@genesis.frugalware.org>
URL: https://gitlist.dev/e/20090303233058.GE4371%40genesis.frugalware.org
In-Reply-To: <22318714.post@talk.nabble.com>

```
On Tue, Mar 03, 2009 at 01:51:14PM -0800, dealmaker <vinkhc@gmail.com> wrote:
>   I am going to upgrade software to a newer version in my main trunk, I
> decide to download the newer version and checkout the main trunk and  copy
> it over to my main trunk.

Do you mean the 'master' branch by 'main trunk'? Trunk is not in Git's
terminology.

> If the older version has some files that are no
> longer in the newer version, how does git determine whether to keep those
> files or not?  Does it even notify me that those files are no longer needed?

First, I think storing upstream code (that you will never touch) in
version control is a horrible idea, but if you really do it, I would do
something like:

cd /path/to/copy
rm -rf *
cp -a /path/to/new/version/* .
git add -A
git commit -m 'update foo to 2.0'

That will add/update/delete files as you would expect.

```

## Jeff King, 2009-03-04 09:49

Subject: Re: How does Git know which files no longer needed during upgrade?
Message-ID: <20090304094951.GA32433@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20090304094951.GA32433%40coredump.intra.peff.net
In-Reply-To: <20090303233058.GE4371@genesis.frugalware.org>

```
On Wed, Mar 04, 2009 at 12:30:58AM +0100, Miklos Vajna wrote:

> First, I think storing upstream code (that you will never touch) in
> version control is a horrible idea, but if you really do it, I would do
> something like:
> 
> cd /path/to/copy
> rm -rf *
> cp -a /path/to/new/version/* .
> git add -A
> git commit -m 'update foo to 2.0'

Nit: "rm -rf *" will miss files starting with '.'. So it is probably
simpler to say what you mean: delete all files managed by git:

  git ls-files -z | xargs -0 rm -f

-Peff

```

## Stefan Näwe, 2009-03-04 12:28

Subject: Re: How does Git know which files no longer needed during upgrade?
Message-ID: <loom.20090304T122643-455@post.gmane.org>
URL: https://gitlist.dev/e/loom.20090304T122643-455%40post.gmane.org
In-Reply-To: <20090304094951.GA32433@coredump.intra.peff.net>

```
Jeff King <peff <at> peff.net> writes:

> 
> > cd /path/to/copy
> > rm -rf *
> > cp -a /path/to/new/version/* .
> > git add -A
> > git commit -m 'update foo to 2.0'
> 
> Nit: "rm -rf *" will miss files starting with '.'. So it is probably
> simpler to say what you mean: delete all files managed by git:
> 
>   git ls-files -z | xargs -0 rm -f
> 
> -Peff

But maybe one wants to keep a .gitignore file. 

Regrads,
Stefan

```

## Jeff King, 2009-03-04 12:38

Subject: Re: How does Git know which files no longer needed during upgrade?
Message-ID: <20090304123813.GA17521@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20090304123813.GA17521%40coredump.intra.peff.net
In-Reply-To: <loom.20090304T122643-455@post.gmane.org>

```
On Wed, Mar 04, 2009 at 12:28:07PM +0000, Stefan Näwe wrote:

> > > cd /path/to/copy
> > > rm -rf *
> > > cp -a /path/to/new/version/* .
> > > git add -A
> > > git commit -m 'update foo to 2.0'
> > 
> > Nit: "rm -rf *" will miss files starting with '.'. So it is probably
> > simpler to say what you mean: delete all files managed by git:
> > 
> >   git ls-files -z | xargs -0 rm -f
> 
> But maybe one wants to keep a .gitignore file. 

True. The problem is that you have no way of saying "give me all the
files that git cares about, except the ones that I put there manually
and not from this tarball." If you guess that dot-files are manual and
everything else isn't, then that is easy, but not necessarily right.

If you tagged the last import, you use "git ls-tree" to get you the list
of files just from the tarball.

-Peff

```
