本文介绍了在旧的Git提交中修复许可证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一个私有的GitHub存储库,它现在已经存在几年了。在 README.md 文件中有一个许可证,这是不准确的。



现在我想通过固定许可证将这个私人回购变为公共回购。无论如何,所有旧的提交仍然包含旧的(错误的)许可证。



我怎么能解决这个问题?我的第一个想法是,但也许有更好的方法来实现我想要的。



正如你所看到的从另一个问题来看,保持历史并不重要,但是OTOH它也没有受到伤害。



真正的伤害是旧的承诺与错误的许可证。 p>

任何想法?



PS:我想确保没有人能够得到旧的提交,即使他们知道提交的ID。所以,解决方案还必须注意更新远程存储库,例如GitHub。

您可以使用 filter-branch 来做到这一点。首先编写一个小脚本,为给定的提交重写树。例如,以下是在 README.md 中改变某些内容到其他内容 code>文件,如果它存在。

  if [-f README.md];然后
sed's / something / something else / g'README.md> tmp
mv tmp README.md
fi

将其另存为 change.sh ,然后执行以下命令:

  git filter-branch --tree-过滤器/ bin / bash $(pwd)/change.shHEAD 

这会重写所有承诺从HEAD回来。如果您犯了一个错误,您可以使用 git reset 返回到较早的树,然后重试。

I have a currently private GitHub repository which exists for a few years now. In the README.md file there is a license, which is not accurate any more.

Now I would like to turn this private repo into a public one, with the fixed license. Anyway, all of the old commits still contain the old (wrong) license.

How could I solve this? My first idea was to squash the repository to a single commit and destroy everything else, but maybe there is a better way to achieve what I want.

As you can see from the other question, keeping history is not important, but OTOH it doesn't hurt as well.

What actually hurts is having old commits with the wrong license.

Any ideas?

PS: I want to ensure that nobody is able to get an old commit, not even if they know the commit's id. So, the solution to this must also pay attention to updating the remote repositories, such as GitHub.

解决方案

You can use filter-branch to do this. First write a small script that rewrites the tree for a given commit. e.g., Following is something that changes something to something else in the README.md file only if it exists.

if [ -f README.md ]; then
    sed 's/something/something else/g' README.md > tmp
    mv tmp README.md
fi

Save this as change.sh and then run the following

git filter-branch --tree-filter "/bin/bash $(pwd)/change.sh" HEAD

This will rewrite all the commits going back from HEAD. If you've made a mistake, you can go back to the earlier tree using git reset and try again.

这篇关于在旧的Git提交中修复许可证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:27