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

Re: how do i re-add a file?

From
James Sadler <freshtonic@gmail.com>
Date
Apr 1, 2008, 11:41 UTC
Message-ID
<e5e204700804010441r61d365d6se0f58c2f49d3058@mail.gmail.com>
In-Reply-To
<47F21814.6000705@tikalk.com>
There are at least a couple of ways to do this.
git show <revision>:<file_name>
e.g. git show HEAD^:builtin-log.c

That will output the content to the console of the file 'builtin-log.c' at the parent revision of the current commit. You can redirect it to a file if you want.

git checkout <rev> <file_name>
e.g. git checkout HEAD^ builtin-log.c

Works the same as above, except the file will be written to your working tree without you having to redirect the output to a file.

Take a look at the help for 'checkout' and 'show'. (e.g. git checkout --help )

In the above examples, 'HEAD^' is just a shortcut for specifying a revision without entering the entire SHA1 of the commit. See http://www.kernel.org/pub/software/scm/git/docs/git-rev-parse.html for more information on the various ways you can specify revisions.

Another way to look at file content at a particular revision is via the 'gitk' GUI tool that comes with git. Fire it up by entering 'gitk' at the command line while inside your repo. In the pane on the left, select the revision that you are interested in. On the bottom-right pane, select the radio button labeled 'tree' and navigate through that to find you file. When you select it, the content of the file will be displayed on the bottom-left pane.

-- 
James.

On 01/04/2008, Ittay Dror <ittayd@tikalk.com> wrote:
> I did git-rm on a file and committed. Made some changes to my sources
>  and committed. Now I want the file back. How can I do that? Related to
>  that, how do I revert my files to some past commit state so that the
>  commits in between are kept in the history?
>
>  Thank you,
>  Ittay
>
>  --
>  Ittay Dror <ittayd@tikalk.com>
>  Tikal <http://www.tikalk.com>
>  Tikal Project <http://tikal.sourceforge.net>
>
>
>  --
>  To unsubscribe from this list: send the line "unsubscribe git" in
>  the body of a message to majordomo@vger.kernel.org
>  More majordomo info at  http://vger.kernel.org/majordomo-info.html
>


-- 
James
Previous: Ittay DrorNext: Miklos Vajna
Message 2 of 3 in “how do i re-add a file?”
  1. Ittay DrorApr 1, 2008
  2. James SadlerApr 1, 2008
  3. Miklos VajnaApr 1, 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.