Home > other >  How to merge a specific file from one branch to master?
How to merge a specific file from one branch to master?

Time:02-02

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 below is the output for above command

Could you let me know the command which merges specific file from specific folder to master.

CodePudding user response:

You need to create a pull request from the branch you are planning to merge with the Master branch. Push all your local branch changes to the remote and then create a pull request to merge with master.

For example if your local branch name is fea/local_1 then after your changes run the following commands.

git add file_name 

to add the specific files or

git add .

to add all. After you add the files then commit the changes with this command.

git commit -m "commit message"

And then push all your changes to remote with the command below

git push origin fea/local_1

Now after this go to your version control server bit bucket or git depending on what you use create a PR from your branch to the Master branch.

CodePudding user response:

You can use restore command, being on a master branch: git restore --source=branch_name /path/to/file

This is sort of an abuse because this command semantically is not meant to do such things but it will work. Also in docs written that this is still experimental and behavior may be changed.

  •  Tags:  
  • Related