Home > Mobile >  If I change a file name on a branch, and then merge it back into the master, will I end up with both
If I change a file name on a branch, and then merge it back into the master, will I end up with both

Time:01-28

For a new feature, I need to change the a method interfaces of some functions in my support libraries to accommodate the feature.

If I start a new branch, and change the name of the library (a typescript class) and the name of the file that contains it, when I merge the new branch back into 'master', will I preserve the old file and class name, and also have the new file and class available in the repo? Or will the old file name and old version be merged out of existence?

CodePudding user response:

Git sees a rename as deleting the old file and creating a new one. Think of the merge as if the branch deleted the old file.

If master has altered the original file...

You will get a conflict in the old file.

This is because Git sees the rename as deleting the old file, while master is changing that file. In which case you need to resolve the conflict and decide what to do. This protects you from overwriting someone else's work.

If master has not altered the original file...

It will apply the rename (delete the old, create the new) and you will only get the new file.

CodePudding user response:

When you create a new branch and change the name of a library and the file that contains it, and then merge that branch back into master, the old file and class will be replaced by the new version in the master branch.

The old version of the file and class will not be preserved in the repository. This is because when you merge the new branch back into master, the changes made in the new branch (including renaming the file and class) will be applied to the master branch, overwriting the previous version.

If you want to preserve the old version of the file and class, you could consider doing the following:

Keep the old version of the file and class in the master branch, and rename the new version to a different name. Create a new branch and make the changes to the new version of the file and class, and merge it into the master branch as a new feature, not as a replacement.

  •  Tags:  
  • git
  • Related