# Deleted files can't be checked back out?

4 messages from 2008-05-23 to 2008-05-25. Participants: fREW, Chris Frey, Jakub Narebski.
Thread: https://gitlist.dev/t/13629

## fREW, 2008-05-23 04:28

Subject: Deleted files can't be checked back out?
Message-ID: <fb3648c60805222128v1a425c60kc8e44f3a2fb41d54@mail.gmail.com>
URL: https://gitlist.dev/e/fb3648c60805222128v1a425c60kc8e44f3a2fb41d54%40mail.gmail.com

```
Hello all,

I recently deleted a bunch of files and checked the change into git,
and then changed my mind and wanted the files back.  I did a
git-checkout <file> and got each file back individually.  Then I did
some work and did a git-push to upload to github. Then I did more work
and tried to do a git push and it gave me an error that apparently
meant I had to pull before I pushed.  Anyway, I pulled, it redeleted
the files and now when I do git-checkout <file> to get them back it
says:

error: pathspec 'foo' did not match any file(s) known to git.

I'd really appreciate some help on this issue. I tried messing with
qgit to look at it, but I didn't have much luck...

-fREW

```

## Chris Frey, 2008-05-23 06:28

Subject: Re: Deleted files can't be checked back out?
Message-ID: <20080523062821.GA24411@foursquare.net>
URL: https://gitlist.dev/e/20080523062821.GA24411%40foursquare.net
In-Reply-To: <fb3648c60805222128v1a425c60kc8e44f3a2fb41d54@mail.gmail.com>

```
On Thu, May 22, 2008 at 11:28:57PM -0500, fREW wrote:
> I recently deleted a bunch of files and checked the change into git,
> and then changed my mind and wanted the files back.  I did a
> git-checkout <file> and got each file back individually.  Then I did

I believe you want to undo the change you made (deleting files), not
just view an old version of the file, which is what checkout does.

You can either add it back yourself, or you can undo the last commit, using
git-reset.

Here's an example of what you could have done before making further
changes that you wanted to push:

	git rm file
	git commit
	git log			# view your change
	git reset --hard HEAD^	# go back to the HEAD before your change

Think of the chain of commits as a long linked list of changes.  A branch
head is just a pointer to the top of that linked list.  git-reset allows
you to point that HEAD to anywhere in the list, even after going back
in history.  The commits are still there, even if HEAD doesn't explicitly
point to them.

For example, say git log shows commit 1a2b3c4 as HEAD, with commit 7abc983
as its parent.  You can move the HEAD back and forth, like this:

	git reset --hard 7abc983
	git log			# commit 1a2b3c4 is gone!
	git reset --hard 1a2b3c4
	git log			# now it's back!

But in your case, you now have a list of commits that is missing files:

        A -> B -> C
             |    |
             |    (made changes here)
             |
             (deleted files here)

So in this case you likely want to revert commit B, while keeping commit C.

	git log			# get the commit SHA1, let's say it's 04bcb93
	git revert 04bcb93


Take a look at "Git from the bottom up"
	http://www.newartisans.com/blog_files/git.from.bottom.up.php

- Chris

```

## Jakub Narebski, 2008-05-24 00:43

Subject: Re: Deleted files can't be checked back out?
Message-ID: <m38wy04jo1.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m38wy04jo1.fsf%40localhost.localdomain
In-Reply-To: <fb3648c60805222128v1a425c60kc8e44f3a2fb41d54@mail.gmail.com>

```
fREW <frioux@gmail.com> writes:

> I recently deleted a bunch of files and checked the change into git,
> and then changed my mind and wanted the files back.  I did a
> git-checkout <file> and got each file back individually.  Then I did
> some work and did a git-push to upload to github. Then I did more work
> and tried to do a git push and it gave me an error that apparently
> meant I had to pull before I pushed.  

You didn't change history, did you (e.g. using rebase)?

> Anyway, I pulled, it redeleted the files and now when I do
> git-checkout <file> to get them back it says:
> 
> error: pathspec 'foo' did not match any file(s) known to git.

Use "git checkout -- <file>" (or "git checkout HEAD -- <file>") to do
a checkout of a file which is not present in the working area.

-- 
Jakub Narebski
Poland
ShadeHawk on #git

```

## fREW, 2008-05-25 23:37

Subject: Re: Deleted files can't be checked back out?
Message-ID: <fb3648c60805251637p70bc76fdm1947da6b9bf34ca1@mail.gmail.com>
URL: https://gitlist.dev/e/fb3648c60805251637p70bc76fdm1947da6b9bf34ca1%40mail.gmail.com
In-Reply-To: <20080523062821.GA24411@foursquare.net>

```
Just FYI, git revert was exactly what I needed.  If you want to undo
any commit at all git revert is your friend.

Thanks!

-fREW

On 5/23/08, Chris Frey <cdfrey@foursquare.net> wrote:
> On Thu, May 22, 2008 at 11:28:57PM -0500, fREW wrote:
>> I recently deleted a bunch of files and checked the change into git,
>> and then changed my mind and wanted the files back.  I did a
>> git-checkout <file> and got each file back individually.  Then I did
>
> I believe you want to undo the change you made (deleting files), not
> just view an old version of the file, which is what checkout does.
>
> You can either add it back yourself, or you can undo the last commit, using
> git-reset.
>
> Here's an example of what you could have done before making further
> changes that you wanted to push:
>
> 	git rm file
> 	git commit
> 	git log			# view your change
> 	git reset --hard HEAD^	# go back to the HEAD before your change
>
> Think of the chain of commits as a long linked list of changes.  A branch
> head is just a pointer to the top of that linked list.  git-reset allows
> you to point that HEAD to anywhere in the list, even after going back
> in history.  The commits are still there, even if HEAD doesn't explicitly
> point to them.
>
> For example, say git log shows commit 1a2b3c4 as HEAD, with commit 7abc983
> as its parent.  You can move the HEAD back and forth, like this:
>
> 	git reset --hard 7abc983
> 	git log			# commit 1a2b3c4 is gone!
> 	git reset --hard 1a2b3c4
> 	git log			# now it's back!
>
> But in your case, you now have a list of commits that is missing files:
>
>         A -> B -> C
>              |    |
>              |    (made changes here)
>              |
>              (deleted files here)
>
> So in this case you likely want to revert commit B, while keeping commit C.
>
> 	git log			# get the commit SHA1, let's say it's 04bcb93
> 	git revert 04bcb93
>
>
> Take a look at "Git from the bottom up"
> 	http://www.newartisans.com/blog_files/git.from.bottom.up.php
>
> - Chris
>
>

```
