简体   繁体   English

Git - 永久排除文件(删除)从提交到主

[英]Git - Permamently exclude file (deletion) from commit to master

I'm working on a project with two branches: master and develop .我正在开发一个有两个分支的项目: masterdevelop

In the master branch, there's a .github/workflows folder for GitHub Actions.在主分支中,有一个.github/workflows文件夹用于 GitHub 操作。 I don't want that folder in develop .我不希望该文件夹位于develop中。

Unfortunately, a colleague once merged master into develop (for whatever reason), resulting in develop containing the workflows folder.不幸的是,一位同事曾经将master合并到develop中(无论出于何种原因),导致develop包含工作流文件夹。 Now, there are so many changes to develop that resetting to before the merge is not an option.现在,要develop的更改太多了,无法选择在合并之前重置。

I have removed the folder from develop by executing git rm.github .我通过执行git rm.githubdevelop中删除了该文件夹。

How do I proceed to merge develop into master without losing the github folder in master ?如何继续将develop合并到master而不会丢失master中的 github 文件夹?

There is no good way to do what you want.没有什么好方法可以做你想做的事。

The real issue here is that git is not designed to have different subsets of content on different branches, and in spite of ostensibly being git experts, the folks at github have decided to work against the grain of that fact[1] by storing what is logically repo-wide metadata in a file in the commits.这里真正的问题是 git 的设计并不是为了在不同的分支上有不同的内容子集,尽管表面上是 git 专家,ZBF215181B5140522137B3D4F6B73544 的人们已经决定反对存储谷物 [1]提交中文件中的逻辑回购范围的元数据。

They don't make it any too obvious in their docs, but a little poking around the support forums confirms that the real workflows integration treats the default branch (usually master ) as "special" in this regard and just ignores any versions of the workflows file other than the one on the current commit of that branch.他们并没有在他们的文档中让它变得太明显,但是在支持论坛上稍作讨论证实了真正的工作流程集成在这方面将默认分支(通常是master )视为“特殊”,并且只是忽略了workflows的任何版本该分支的当前提交上的文件以外的文件。 (They do mention that you can get to other versions of the file - which presumably would allow you to manually kick them off, etc. - by navigating branches or pr's in the web interface.) (他们确实提到您可以通过在 web 界面中导航分支或 pr 来访问该文件的其他版本 - 大概允许您手动启动它们等。)

So if it were me, I wouldn't worry about the file being present in other branches;所以如果是我,我不会担心文件存在于其他分支中; as you're already seeing, it's going to cause more trouble than it's worth, with periodic "leaks" onto other branches and, if you try to clean those up, risk of the one copy that matters being deleted (even if only temporarily).正如您已经看到的那样,它会造成比其价值更多的麻烦,定期“泄漏”到其他分支上,如果您尝试清理这些,则有可能删除一个重要的副本(即使只是暂时的) .


[1] - If that characterization seems unsympathetic to what they're trying to accomplish... well, I guess I am. [1] - 如果这种描述似乎对他们试图完成的事情没有同情心……好吧,我想我是。 It's true that a "good" integration with the git repo would be a bit more complicated;确实,与 git 存储库的“良好”集成会稍微复杂一些。 but they could provide tooling to insulate the user from that pretty easily.但是他们可以提供工具来轻松地将用户与此隔离。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM