用Git改变项目的第一次提交? [英] Change first commit of project with Git?

查看:306
本文介绍了用Git改变项目的第一次提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的项目的第一次提交中改变某些内容,而不会丢失所有后续提交。有没有办法做到这一点?



我意外地在原始代码中的评论中列出了我的原始电子邮件,我想改变它,因为我得到垃圾邮件从垃圾邮件索引GitHub。

解决方案

正如 ecdpalma 以下 git 1.7.12+ (2012年8月)增强了选项 - root for git rebase
$ b

git rebase [-i] --root $ tip 现在可以用于将所有导致 $ tip 的历史记录重写为根提交。



新行为最初是在这里讨论


我个人认为 git rebase -i --root 应该在不需要 - 到的情况下工作,并让您编辑即使是第一个在历史上。
可以理解的是,没有人会打扰,因为人们在历史的开端附近重写的次数往往比其他时候更少。






<原始答案,2010年2月>

>

正如 Git FAQ (和这个 SO问题),这个想法是:


  1. 创建新的临时分支

  2. 将它倒回到您要更改的提交中 git reset --hard

  3. 更改该提交(它将成为当前HEAD的顶部,并且您可以修改任何文件的内容)
  4. 改变提交之前的Rebase分支,使用:
    $ b

      git rebase --onto< tmp分支> <更改后提交> < b> 


请确保您要删除的信息不会由稍后在文件中的其他位置再次提交。如果您怀疑,那么您必须使用 filter-branch - tree-filter 来确保该文件的内容在任何提交中都不包含合理的信息。



在这两种情况下,您最终会重写每个提交的SHA1,因此如果您已发布要修改其内容的分支,请注意。你可能不应该这样做,除非你的项目尚未公开,而其他人没有从你将要改写的提交中找到工作。

I want to change something in the first commit of my project with out losing all subsequent commits. Is there any way to do this?

I accidentally listed my raw email in a comment within the source code, and I'd like to change it as I'm getting spammed from bots indexing GitHub.

解决方案

As mentioned by ecdpalma below, git 1.7.12+ (August 2012) has enhanced the option --root for git rebase:

"git rebase [-i] --root $tip" can now be used to rewrite all the history leading to "$tip" down to the root commit.

That new behavior was initially discussed here:

I personally think "git rebase -i --root" should be made to just work without requiring "--onto" and let you "edit" even the first one in the history.
It is understandable that nobody bothered, as people are a lot less often rewriting near the very beginning of the history than otherwise.

The patch followed.


(original answer, February 2010)

As mentioned in the Git FAQ (and this SO question), the idea is:

  1. Create new temporary branch
  2. Rewind it to the commit you want to change using git reset --hard
  3. Change that commit (it would be top of current HEAD, and you can modify the content of any file)
  4. Rebase branch on top of changed commit, using:

    git rebase --onto <tmp branch> <commit after changed> <branch>`
    

The trick is to be sure the information you want to remove is not reintroduced by a later commit somewhere else in your file. If you suspect that, then you have to use filter-branch --tree-filter to make sure the content of that file does not contain in any commit the sensible information.

In both cases, you end up rewriting the SHA1 of every commit, so be careful if you have already published the branch you are modifying the contents of. You probably shouldn’t do it unless your project isn’t yet public and other people haven’t based work off the commits you’re about to rewrite.

这篇关于用Git改变项目的第一次提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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