0

After I git clone the repo, my colleague made a commit which touched several files. The commit is currently in a merge request, not merged to gitlab yet.

I want to retrieve just 2 files from his commit into my local directory, not all the files in the commit. I have the commit hash tag. Can you show me how I should do it?

my_question
  • 3,075
  • 2
  • 27
  • 44
  • 2
    Duplicate of https://stackoverflow.com/questions/307579/how-do-i-copy-a-version-of-a-single-file-from-one-git-branch-to-another https://stackoverflow.com/questions/2364147/how-to-get-just-one-file-from-another-branch – bosowski Feb 07 '23 at 01:25

1 Answers1

1

You can do something like: git checkout remoteName/branchName path/to/file.

This will basically "copy" over the file to your directory and stage the it. For multiple files you can do path/to/file1 path/to/file2 instead of the path/to/file etc.

bosowski
  • 124
  • 6
  • Might also need `git fetch remoteName branchName`. – konsolebox Feb 07 '23 at 01:51
  • If doing a checkout of a remote commit there is no need to do a fetch first. If you do not specify the remote - implying that the commit is available locally and it is not then you might have issues. That's why I included the remoteName in the answer. – bosowski Feb 07 '23 at 01:55
  • It may be available locally. The question is if it's updated. – konsolebox Feb 07 '23 at 01:59