Drupal, Flex, Sass,React, Website Development

Git merge branch and commit individual files

You are here

Merging two Git branches and then commiting each merge file seperaterly looks easy except while in a merge Git will not let you do it. This howto will explain one way how to do it. Firstly go to the terminal window and move to the Git directory that you want to merge. In this example I am going to merge the large-branch-to-be-merge into the master. Check out the master branch or the branch you want to merge like the example below.

~$ git checkout master
~$ git branch
large-branch-to-be-merge
*master

The next step is to do the merge so that your wonderful new set of code will make the amazing changes to the software.

~$ git merge large-branch-to-be-merge

After the merge command there could be some confilcts that need to be resolved and you may see something like this.

Fix the confilcts if needed by opening the files and fixing the code. If you were to try and commit the files individually at this point Git would not let you as you are in the middle of a merge.

Solution to Git merge branch and commit individual files

The solution was very easy I just checked out the master branch again and this completed the merge and then allowed me to start committng each file .

~$ git checkout master

For anyone that does not know how to commit an individual file use the command below. Remember the -- are needed. -m allows you to add a comment on the command line and if your Git repo is attached to a version control system then the reference to it will go in the talking marks.

~$ git commit -m "I want to add some comments and reference for version control #bug-number" -- mypath/file.php