how to merge specific files in git

前端 未结 4 759
傲寒
傲寒 2021-01-04 09:48

Suppose I have a project on MASTER branch with 100s of php files. To do a bug fixing in the project, i create a separate branch

git checkout -b bugfix
         


        
4条回答
  •  别那么骄傲
    2021-01-04 10:28

    You can simulate the behaviour you want but what happens with the changes you did on the third file?

    The changes on the third file remain in the commits on the branch but they will not be present in the merged commit, it's like the file was not modified on the branch at all.

    This is how you can do it:

    git checkout master
    git merge bugfix --no-commit
    

    The --no-commit option tells git to merge the files but stop before committing them. You can now inspect the files, change them, do whatever you want. In order to cancel the changes you did on index.php you can run:

    git checkout master -- index.php
    

    Running git status you can see that index.php does not appear as modified any more (neither in the index or in the working tree). You can now git commit and that's all.

提交回复
热议问题