Skip to contentSkip to conversation

how do i re-add a file?

DISCUSSION Ittay Dror 3 participants 3 messages Jun 15, 2016

lore
Share & tools
lore

Ittay Dror

author
#0 lore raw

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

Signature · 3 lines
Ittay Dror <[email protected]>
Tikal <http://www.tikalk.com>
Tikal Project <http://tikal.sourceforge.net>
#1 lore raw
Quoted 4 lines · Ittay Dror

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?

git checkout HEAD^ -- path/to/file

#2 lore raw
In reply to Ittay Dror

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.

Signature · 1 line
James.
Quoted 19 lines · Ittay Dror

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 <[email protected]>
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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
James