git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Deleted files can't be checked back out?

From
CFChris Frey <cdfrey@foursquare.net>
Date
May 23, 2008, 06:28 UTC
Message-ID
<20080523062821.GA24411@foursquare.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
Previous: fREWNext: fREW
Message 2 of 4 in “Deleted files can't be checked back out?”
  1. fREWMay 23, 2008
  2. Chris FreyMay 23, 2008
  3. fREWMay 25, 2008
  4. Jakub NarebskiMay 24, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.