为什么运行git过滤器后有重复的提交? [英] Why do I have duplicate commits after running a git filter?

查看:170
本文介绍了为什么运行git过滤器后有重复的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在git存储库上运行以下命令,强制所有文本文件使用unix行结束符。

  git filter-分支--force --tree-filter'git ls-files | xargs文件| sed -n -e/.*:。* text。* / s / \(。* \):。* / \ 1 / p| xargs dos2unix'--tag-name-filter cat  -  --all 

根据git log这导致了存储库中每次提交的重复提交,作者日期和注释是相同的,散列与预期的一样是新的。这是我应该预料到的吗?我认为它会用不同版本的文件替换现有的提交。



有没有更好的方法可以进行不会导致所有多余提交的转换?

解决方案

Git提交是不可变的,所以无论何时您想更改关于给定提交的 ,您实际上都必须创建一个新的提交。这包括文件内容,作者日期/时间或父提交。 (因此,如果您在一次提交中更改了内容,则必须为后面的所有提交创建新的提交。)

所以是的,这是您应该期望的,并且不,没有办法做到不产生新提交的转换。任何重写历史的命令都是如此,其中包括 rebase 以及 filter-branch



阅读更多关于如何在 Pro Git书中的Git Internals - Git Objects 部分。


I ran the following command on my git repository to force all text files to use unix line endings.

git filter-branch --force --tree-filter 'git ls-files | xargs file | sed -n -e "/.*: .*text.*/s/\(.*\): .*/\1/p" | xargs dos2unix' --tag-name-filter cat -- --all

According to the git log this resulted in a duplicate commit for every commit in the repository, author date and comment are same, hash as expected is new. Is that what I should have expected? I thought it would replace the existing commits with different versions of the files.

Is there a better way to do the conversion that wouldn't result in all the extraneous commits?

解决方案

Git commits are immutable, so any time you want to change anything about a given commit, you actually have to create a new commit instead. This includes file content, author date/time, or parent commit. (Thus, if you change the content in one commit, you must create new commits for all those that follow.)

So yes, this is what you should expect, and no, there isn't a way to do the conversion that doesn't produce new commits. This is true for any commands that rewrite history, which includes rebase as well as filter-branch.

Read more about how this works in the Git Internals - Git Objects section in the Pro Git book.

这篇关于为什么运行git过滤器后有重复的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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