12

Imagine that I have a repository with directories Dir1 and Dir2 and I am in branchA.

Imagine that I want to get rid of contents of Dir2 and replace them with Dir2 in the master branch, while keeping the content of Dir1.

I don't expect this to be that simple, but ideally :

cd Dir2
git [magic that replaces current dir with the contents of master branch]
kms333
  • 3,147
  • 7
  • 31
  • 39
  • check this [out](http://stackoverflow.com/questions/307579/how-do-i-copy-a-version-of-a-single-file-from-one-git-branch-to-another) – ziu Sep 13 '12 at 10:37

1 Answers1

20

remove Dir2 from branchA and
fetch it from master branch:

$ git checkout branchA
$ git rm -r Dir2
$ git checkout master -- Dir2
$ git commit -m "replaced Dir with Dir2 from master"
c00kiemon5ter
  • 16,994
  • 7
  • 46
  • 48
  • cool! I was under the impression that you would have to checkout the whole repository. Do you happen to know how to do this in eGit or TortoiseGit ? – kms333 Sep 13 '12 at 15:07
  • Is it possible to do it with another upstream ? `git checkout notorigin:master -- Dir2` – Dimitri Kopriwa Jun 28 '17 at 06:25