0 votes
1 view
in Devops and Agile by (19.8k points)

I am working on a Git branch that has some broken tests, and I would like to pull (merge changes, not just overwrite) these tests from another branch where they are already fixed.

I know I can do

git pull origin that_other_branch

but this will attempt to merge lots of other files, for that I am not yet ready.

Is it possible to pull and merge only the specified file (and not everything) from that another branch?

1 Answer

0 votes
by (63.4k points)

You can simply perform fetch which will download all the changes done from your remote repository to your local repository and then check out to that one file in the following way:

git fetch

git checkout -m <revision> <yourfilepath>

git add <yourfilepath>

git commit

Regarding the git checkout command: <revision> - a branch name, i.e. origin/master <yourfilepath> does not include the repository name (that you can get from clicking copy path button on a file page on GitHub), i.e. README.md

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...