1

When I git checkout branch -- app/ expect overwrite all my local files in app folder by the content of app folder from another branch. But in reality it overwrite same named files, but don't delete files that exists only in my app folder. And the resulting folder is not the same as in target branch. Why does it work this way and how to checkout whole folder without leaving old files?

ogbofjnr
  • 1,688
  • 5
  • 19
  • 41
  • It is called **`git restore`** nowadays (Git 2.23+, August 2019): see https://stackoverflow.com/a/57066072/6309 and https://stackoverflow.com/a/58003889/6309 – VonC Dec 23 '19 at 15:35

1 Answers1

2

When used with a tree-ish and a path, git-checkout checks out matching files in the path from the tree.

It does not touch other files. If you want to copy that folder exactly from another branch, you probably have to

git rm path
git commit
git checkout branch -- path

But why do you need to do this anyway?

Alternately, I suppose you could clone the repository in another directory nearby, and then just

git -C newrepo checkout branch
mv newrepo/path oldrepo/path
rm -r newrepo
D. Ben Knoble
  • 4,273
  • 1
  • 20
  • 38