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
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.