Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As mentioned by <a href="https://stackoverflow.com/users/656927/ecdpalma">ecdpalma</a> <a href="https://stackoverflow.com/a/14629246/6309">below</a>, <a href="https://github.com/git/git/blob/master/Documentation/RelNotes/1.7.12.txt" rel="noreferrer">git 1.7.12+</a> (August 2012) has enhanced the option <code>--root</code> for <code>git rebase</code>:</p> <p>"<code>git rebase [-i] --root $tip</code>" can now be used to rewrite all the history leading to "<code>$tip</code>" down to the root commit.</p> <p>That new behavior was initially <a href="http://git.661346.n2.nabble.com/Editing-the-root-commit-td7561714.html" rel="noreferrer">discussed here</a>:</p> <blockquote> <p>I personally think "<code>git rebase -i --root</code>" should be made to just work without requiring "<code>--onto</code>" and let you "edit" even the first one in the history.<br> It is understandable that nobody bothered, as people are a lot less often rewriting near the very beginning of the history than otherwise. </p> </blockquote> <p>The <a href="http://comments.gmane.org/gmane.comp.version-control.git/200687" rel="noreferrer">patch followed</a>.</p> <hr> <p>(original answer, February 2010)</p> <p>As mentioned in the <a href="http://git.wiki.kernel.org/index.php/GitTips#How_to_change_commits_deeper_in_history" rel="noreferrer">Git FAQ</a> (and this <a href="https://stackoverflow.com/questions/2119480/changing-the-message-of-the-first-commit-git">SO question</a>), the idea is:</p> <ol> <li>Create new temporary branch </li> <li>Rewind it to the commit you want to change using <code>git reset --hard</code></li> <li>Change that commit (it would be top of current HEAD, and you can modify the content of any file)</li> <li><p>Rebase branch on top of changed commit, using:</p> <pre><code>git rebase --onto &lt;tmp branch&gt; &lt;commit after changed&gt; &lt;branch&gt;` </code></pre></li> </ol> <p>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 <a href="http://git-scm.com/docs/git-filter-branch" rel="noreferrer"><code>filter-branch --tree-filter</code></a> to make sure the content of that file does not contain in any commit the sensible information.</p> <p>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. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload