Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy directory from another branch

Tags:

git

There is a question "Git: copy all files in a directory from another branch" which shows how. But it doesn't delete files that are in the current branch, but that are deleted in the other branch.

There are few solutions I usually use:

  1. Delete the directory locally rm -r dir, then do git checkout otherBranch -- dir. It works, but is slow for large directories.

  2. git checkout dir and then git rm $(git diff --name-only otherBranch -- dir). It works, but I think there should be a better solution.

Is there an easier way to do it?

like image 562
kan Avatar asked Aug 15 '14 19:08

kan


Video Answer


1 Answers

git reset otherBranch -- dir
git clean -df
git checkout .

This should update the contents of dir with those of the same directory on the other branch.

like image 90
andi5 Avatar answered Oct 17 '22 03:10

andi5