Git ignore files per branch or remote repository

巧了我就是萌 提交于 2019-12-24 03:23:00

问题


Used

Git, Github.com

Problem

I have a project with files: A, B, C, D, E.

  • I would like Team 1 work on: A, C, D (do not want to expose B, E to them)
  • While Team 2 work on: B, D, E (do not want to expose A, C to them)
  • And I would like to work on: A, B, C, D, E

Then I pull Team 1 work and get A, C, D merged with my work and then pull Team 2 work and get B, D, E merged with my work.

I can create a repo per team if needed.

Not working

I have read all articles and tried everything they provided.

  • Submodules not working for me - files are in different locations and I will need to ignore different bunch of files for each developer team
  • Excludesfile per branch just doesn't work
  • .gitignore will delete those 2-3 files when I pull

I do not want to believe there is no easy and elegant solution just to ignore some files per push or branch or remote repo or something else...

Additions

  • I cannot separate one project into several projects

回答1:


I would create three projects:

  • D (common, visible to all)
  • A and C (visible to you and Team 1), dependency on D
  • B and E (visible to you and Team 2), dependency on D

I would further split projects if I envisage ever wanting finer access control that separates A from C or B from D.

I don't think I would try to use ignore files for access control.




回答2:


Git has no access-control, so: "git", "secret files", and "easy to maintain" just doesn’t mix well. Look at gitolite and Git on the server - gitolite if you want to add an access control layer.

You will need to experiment, but you can probably work along the lines of starting with an empty repo, and having a branch per-team. Note however that you don’t want the files appearing in any of the respective branch histories. For example, you don’t want to have a master branch with all the files, that you branch as a team1 branch, and then git rm the files. The “secret” files will remain in the branch history, and restricting access won't help. So you will either have to have a clear separation for the files across branches, or have a sanitation script that applies git filter-branch to remove files every time you decide to merge and run the risk of introducing the files again.

To elaborate on the last example. Suppose you merged team2 work into your master branch and now want to share the overall progress with team1. You cannot simply merge master into team1, but you can branch master as master-sanitized, run filter-branch to remove the files team1 shouldn't see, and then merge master-sanitized into team1, discarding the temporary branch. However all that won't save you from the fact that rewriting commits is actually re-introducing them with new sha1-s, so your merges will be a constant pain of conflict resolution with -s ours or -X theirs.



来源:https://stackoverflow.com/questions/22334400/git-ignore-files-per-branch-or-remote-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!