I have a master branch with 3 files:
feature1.txt
feature2.txt
feature3.txt
Now I create new branch call feature3 based on the master branch.
I will only work on file feature3.txt on this branch. I don't need the other 2 files. I want to remove them, but if I do, they will be removed from the master branch as well once I do a merge of the feature3 branch into the master branch.
What do I need to do to have these 2 files removed/hidden from branch feature3, without that the master branch is impacted?
CodePudding user response:
You can‘t create a branch for a single file in Git. When you create a branch, you create a branch for the entire repo (like a copy from the repo).
It is quite normal that not all available files in a branch are always processed. You only change those files that are necessary to complete the activities in this branch. So I see no problem that the other two files (feature1.txt
and feature2.txt
) are in this branch, although these are not changed.
CodePudding user response:
As long as you don't commit the removal of files, you won't impact your master branch. If you would prefer not to see the deleted files showing as needing to be committed in git status
, you can run the following:
git update-index --assume-unchanged path/to/file
This causes git ignore all changes (including a deletion) for a given file or files. Unfortunately, this approach is not limited to a single branch so you'll need to revert this setting when you switch to a different branch:
git update-index --no-assume-unchanged path/to/file
There are some useful git aliases for managing files that are flagged in this way detailed elsewhere on StackOverflow.