如何在忽略新文件的同时获取 git 存储库中文件的更改
我有一个 git 存储库,其中有一个文件夹,其中包含自动生成的源代码文件。随着时间的推移,对该代码进行了一些轻微的手动修改。我现在需要重新生成文件,但我不想错过所做的任何更改。
我想做的是获取一段时间内对该文件夹所做的所有更改的差异,但排除每个文件的原始“添加”。这样我就可以将差异应用到新的文件集。
还有一个更重要的细节:并非所有文件都是同时添加的。添加与编辑混合在一起。因此,这并不像从特定提交开始生成差异那么简单。
有什么想法吗?
更多上下文:
- 自动生成的文件是从 WSDL 文件生成的 SOAP 代理类。
- 我们正在处理多个服务,因此这些类是根据需要添加的。
- 我们收到了带有 WSDL 的更新服务器虚拟机,其中包含一些小修复
- 用于生成代理类的工具有一些不完整的实现,因此对这些文件所做的更改可以解决
SEEDS:
- 有没有办法知道第一次提交的 SHA一个文件?我猜是
git log
与grep
或sed
的风格? - 也许获取特定文件的提交计数,其中 1 == 没有更改,只有插入,我可以将它们 grep 出来?
I have a git repo with a folder that contains files that are auto-generated source code. Overtime, there were some slight manual modifications made to that code. I am now in a position where I need to regenerate the files but I don't want to miss any of the changes that were made.
What I'd like to do is get a diff of all changes made to that folder over time, but to exclude the original 'add' of each file. That way I could just apply the diff to the new set of files.
There is one more important detail: not all files were added at the same time. The adds are mixed in with the edits. So it's not as simple as generating a diff starting from a specific commit.
Any ideas?
MORE CONTEXT:
- The auto generated files are SOAP proxy classes that are generated from WSDL files
- We are dealing with more than one service and so the classes were added as they were needed.
- We received an updated server VM with WSDLs that contain minor fixes
- The tool used to generate the proxy classes has some incomplete implementations and so the changes made to those files were work arounds
SEEDS:
- Is there a way to know the SHA of the first commit of a file? A flavor of
git log
withgrep
orsed
I guess? - Perhaps get a count of commits on a specific file where 1 == no changes only an insert and I could grep those out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您仍然拥有 WSDL 的旧副本,并且是一名优秀的源代码控制用户。考虑到这一点,我会执行以下操作:
有问题的文件已添加。
这会将自动生成的文件的差异与您的手动调整合并。
保留该分支,以便每次 WSDL 更改时,您都可以检查该分支并重复最后两个步骤。基本上,该分支应始终仅包含自动生成的文件。
I'm assuming you still have the old copy of the WSDLs, being a good source control user and all. With that in mind, I would do the following:
files in question were added.
That will merge the differences of the auto-generated files with your manual tweaks.
Keep that branch around, so that every time the WSDLs change, you can check that branch out and repeat the last two steps. Basically, that branch should always contain only the auto-generated files.
修订后的答案:
您将需要一些脚本来遍历该目录并使用每个文件获取初始提交
git log --format=%H 文件名 | tail -1
然后获取差异:
git diff ^output_of_above SHA_last_commit 文件名
Revised answer:
You will need some script that will walk through that directory and using each file get the initial commit with
git log --format=%H fileName | tail -1
And than get the diff with:
git diff ^output_of_above SHA_last_commit fileName