Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git pull --rebase for a specific folder/file

I only want to rebase one folder.

Is it possible to do something like

git pull --rebase origin/master path/to/folder/or/file.txt

and only that path will be updated?

like image 974
onepiece Avatar asked Dec 20 '22 10:12

onepiece


2 Answers

The quick answer is "no".

The longer answer depends on what you are trying to accomplish, and whether or not you have any changes to any of the files/folders you want to rebase, and what if any history you are interested in showing.

If you have no changes on your branch, and you just want to grab the latest file from origin/master and put it in your working directory, and you don't want there to be any 'history' of what happened, then you could do

git fetch origin master
git checkout origin/master -- path/to/file.txt 

For anything more complicated than that it gets ugly fast.

like image 105
Andrew C Avatar answered Dec 21 '22 22:12

Andrew C


My idea for this is something along the lines:

git cherry-pick $(git log --oneline HEAD..origin/master -- path/to/something | cut -d' ' -f1 | tac| xargs echo)

[Edit] As suggested by @CervEd there is a more straightforward way

git cherry-pick $(git rev-list HEAD..origin/master -- path)
like image 41
Paulo Neves Avatar answered Dec 21 '22 23:12

Paulo Neves