'How to merge a specific file from one branch to master?
I have a branch named test and i want to merge it to master. i am using below git diff command in shell script to get the changed file name
->master=git diff release/1..master --name-only . ':(exclude)*.yml' ':(exclude)*.yml' ':(exclude)*.gitmodules'
master variable has all the file names such as test1.py test2.py and template/test3.py
I tried using below command but not able to merge it
git checkout master
git checkout release/1 $master
Could you let me know the command which merges specific file from specific folder to master?
Solution 1:[1]
If you need to take just one file from branchX to current one:
git checkout branchX -- path/to/file
then commit.
If need to create merge commit but drop any changes except one file (not recommented!)
git merge branchX --no-commit
git checkout -f ## drop any changes
git checkout branchX -- path/to/file
git commit ## create merge commit with the only file taken from source branch
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
