稀疏签出后过滤git commit历史记录 [英] filter git commit history after sparse checkout

查看:88
本文介绍了稀疏签出后过滤git commit历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git repo下有数十个文件夹;但我只与其中之一合作.因此,我不想知道其他文件夹下的项目正在发生什么. 我启用了稀疏检出功能,从远程检出了一个分支,现在本地只有一个文件夹.但是我仍然可以在使用gitk时看到完整的提交历史记录.在交互式基础调整过程中进行一些更改时,我也会看到它.

There are dozens of folders under git repo; but I work with one of them only. So, I don't want to know what's happening with projects under other folders. I checked out a branch from remote with enabled sparse checkout and now I have only one folder locally; but I still can see full commits history when using gitk. I also see it when doing some changes during interactive rebase.

我的问题是:是否有可能以某种方式清除(过滤器)提交历史记录,以便在重新设置基准时仅看到与特定文件夹相关的内容?想法是使用存储库,就像只包含一个文件夹一样.

My question is: Whether it's possible to somehow clean (filter) commits history so that I saw only ones related to particular folder when rebasing? Idea is to work with the repo same way as if it contained only one folder.

谢谢

推荐答案

对于读取操作,通常可以通过传递路径选项来获得所需的内容.

For read operations, you can often get what you want by passing path options.

git log -- ./the_one_folder

gitk -- ./the_one_folder

但是对于编写的操作(如变基),没有一般的方法可以执行您描述的操作.如果您将所有内容都提交给一个重要的历史记录,那么该历史记录实质上就是每次提交的一部分.因此,您有一个更改the_one_folder的提交,即使其父级未更改与父级属于提交的目录相同的文件夹中的任何内容,也无法好像它不在那里"那样进行变基.

But for operations that write, such as rebase, there is no general way to do what you describe. If you commit everything to one big history, then that history is essentially a part of each commit. So you have a commit that changes the_one_folder, even if its parent doesn't change anything in the same folder that parent is part of the commit and you can't do a rebase "as though it weren't there".

您可以进行重新配置,以删除所有不需要的提交,但是这些提交将从您重新定基础的分支中删除.因此,基本上,您必须为您的目录提供一组分支,并为下一个工作人员不断使用的下一个目录提供一组分支.

You could do a rebase that drops all the commits you don't care about, but then those commits are removed from the branch you're rebasing. So basically you'd have to have a set of branches for your directory, and a set of branches for the next directory that the next guy works on, and on and on.

执行完此操作后,开始看起来应该将每个项目放入其自己的存储库中.这是事实.在git中,您不应该将大量项目塞入相同的仓库中.如果您有时确实将各个项目之间的更改关联起来,则有多种方法可以应对.但是听起来至少在大多数情况下它们是独立的,因此,如果您不想一堆乱七八糟的历史记录,则应考虑移至单独的存储库.

And once you do that, it starts to look like you should've put each project in its own repo. And that's a fact. In git, you shouldn't cram a bunch of projects into the same repo. If you do sometimes correlate changes across projects, there are ways to deal with that; but it sounds like at least most of the time these are independent, so if you don't want a bunch of cluttered histories you should consider moving to separate repos.

有一种方法可以创建只是您的项目"的历史记录-意识到只有在您确实要迁移到单独的存储库(或至少是命名空间的独立引用集)的情况下,这才真正有用,但这只是一种更为复杂的方法要做同样的事情,为什么?),因为一旦完成,对单独历史记录的更改将不再反映在合并的历史记录中.

There is a way to create a history of "just your project" - realizing that this is only really useful if you are indeed migrating to separate repos (or at least separate namespaced sets of refs, but that's just a more complicated way to do the same thing so why?) because once its done changes to the separate history will no longer be reflected in the combined history.

git filter-branch --subdirectory-filter the_one_folder --prune-empty -- --all

这篇关于稀疏签出后过滤git commit历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆