Reputation: 14571
I am using my master
branch to hold base 'material' files which are used in child branches for various projects. Let's say I work for a company which makes wagons as well as downhill skis. My master branch would contain all the files which are used as parts for those products. Each product is branched from master
(wagon
branch, ski
branch, etc). The parts not needed for each project are then removed using git rm
(although skis on a wagon do sound like fun).
The problem is, whenever I merge my master
branch (material changes perhaps) into a project branch (wagon for instance) git
thinks I really want the changes to the files which I've git rm
'd into oblivion, and adds them back for me - Version master of skis left in tree as shown code below.
How can I get git
to really and truly forget about a file I've told it to forget about and stop tracking?
add some parts to master
, and commit:
$ pwd
/tmp/parts
$ git init
Initialized empty Git repository in /tmp/parts/.git/
$ echo rubber > wheels
$ echo steel > skis
$ echo vinyl > seat
$ echo wood > sides
$ ls
seat sides skis wheels
$
$ git add .
$ git commit -a -m 'initial parts'
[master (root-commit) ca7610e] initial parts
4 files changed, 4 insertions(+)
create mode 100644 seat
create mode 100644 sides
create mode 100644 skis
create mode 100644 wheels
Create a wagon
project branch and remove the parts that we do not need on a wagon:
$ git checkout -b wagon
Switched to a new branch 'wagon'
$ ls
seat sides skis wheels
$ git rm skis
rm 'skis'
$ git rm seat
rm 'seat'
$ git commit -a -m 'initial wagon design'
[wagon 384b246] initial wagon design
2 files changed, 2 deletions(-)
delete mode 100644 seat
delete mode 100644 skis
The engineering team has decided to change some materials. Commit those changes in master
so they are available to all our projects:
$ git checkout master
Switched to branch 'master'
$ ls
seat sides skis wheels
$
$ echo 'titanium' > skis
$ echo 'metal' > sides
$ git commit -a -m 'design requirements call for stronger sides and skis'
[master a8bf4c4] design requirements call for stronger sides and skis
2 files changed, 2 insertions(+), 2 deletions(-)
We need some of the changes in the wagon
project so merge master
to get them but now git is complaining:
$ git checkout wagon
Switched to branch 'wagon'
$ git merge master
CONFLICT (modify/delete): skis deleted in HEAD and modified in master. Version master of skis left in tree.
Automatic merge failed; fix conflicts and then commit the result.
Upvotes: 0
Views: 96
Reputation: 14571
So far, the most workable solution I've found is to merge master into the current branch and then use --porcelain
to print out a list of Deleted Updated
files and then call xargs
to remove them:
git status --porcelain | awk '{if ($1=="DU") print $2}'
It's not pretty. It would be nice to plug this into a pre-merge
git hook but that apparently does not exist.
Upvotes: 0
Reputation: 189
I think you might be using git not as a source control system but more like a solution manager. Think about it, why would you put files under source control if you want to remove a different part of them whenever you checkout a new branch?
Feature branches are forks on the development path that are intended to be merged with master and bring additional functionality to the entire project.
You can create a repo for each material and then set up a project build to fetch required materials from material repos.
Upvotes: 4