James Atwood
James Atwood

Reputation: 4329

How can I check out a file from another branch into a new file in the current branch with git?

Let's say that I have a file core.clj in branch master at HEAD which is distinct from core.clj in branch other at HEAD, and that I am currently in branch other. I would like to checkout master's core.clj into the current branch with some other file name, say tmp.clj, for easy comparison.

How can I do this?

Upvotes: 5

Views: 92

Answers (3)

twalberg
twalberg

Reputation: 62369

You can use git show master:core.clj to show the file. Redirect it to a new file (git show ... > temp.clj to save it for further processing.

Upvotes: 7

kan
kan

Reputation: 28951

It is very straightforward:

 git checkout master -- core.clj

Upvotes: 1

Jeremy Rodi
Jeremy Rodi

Reputation: 2505

You don't need to; git diff will do exactly what you need to do. git diff master otherbranch core.clj is a basic use of the command, and if you need more help, man git-diff can explain more to you.

Upvotes: 1

Related Questions