Jay Taylor's notes
back to listing indexChange first commit of project with Git?
[web search]- Home
-
- Public
- Stack Overflow
- Tags
- Users
- Jobs
-
This question already has an answer here:
- Edit the root commit in Git? 5 answers
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:
- Create new temporary branch
- Rewind it to the commit you want to change using
git reset --hard
- Change that commit (it would be top of current HEAD, and you can modify the content of any file)
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.
<commit after changed>
to be the same hash I used in the git reset --hard
command. Aside from that one minor change, this works beautifully to update the author information across all commits in a repo.
– berto
Dec 30 '12 at 1:28
git rebase -i --root
worked for me.
– Rémi Benoit
Jun 4 '15 at 17:12
$tip
can be any commit you want. master
(meaning master HEAD
commit) is fine.
– VonC
Jun 4 '15 at 17:13
As stated in 1.7.12 Release Notes, you may use
$ git rebase -i --root
-a
to git commit --amend
or using git add
because I forgot that first time!
– Nick Craig-Wood
Nov 11 '12 at 14:42
If you want to modify only the first commit, you may try git rebase and amend the commit, which is similar to this post: How to modify a specified commit in git?
And if you want to modify all the commits which contain the raw email, filter-branch is the best choice. There is an example of how to change email address globally on the book Pro Git, and you may find this link useful http://git-scm.com/book/en/Git-Tools-Rewriting-History
Get the weekly newsletter! In it, you'll get:
- The week's top questions and answers
- Important community announcements
- Questions that need answers
see an example newsletter
Linked
Related
Hot Network Questions
-
How do dummy tickets/itinerary service websites work?
-
Can piano studies be played as a performance piece?
-
Is it possible to kill someone with a single atom and a particle accelerator?
-
Has there ever been an instance of an active nuclear power plant within or near a war zone?
-
Why Can't I get value_type From iterator_traits?
-
Where can I listen to the actual cockpit voice recorder audio from US Airways Flight 1549?
-
How do I notate a staccato on a unison note?
-
If visible light has more energy than microwaves, why isn't visible light dangerous?
-
Could a Giant Excavator (Like Bagger 293) Breach an armored wall in a Siege?
-
What type of bulb is this?
-
"Variabilize" the ampersand (background a process)
-
Is it bad to project myself into my story?
-
How do we compile and visualize the animations of TikZ 3.1?
-
Do SQL Server compressed indexes remain compressed on rebuild without specifying data compression?
-
Convincing argument about something I don't agree with
-
Is Neighborhood an open set?
-
Rocket flywheel instead of battery/generator (crazy idea)?
-
Why did Harry help Brian?
-
Should a (junior) developer try to push for better processes and practices in their development/IT team?
-
What is the purpose of finding Area between Curves?
-
How to interpret this rejection email from Journal of American Math Society? Anything to read between the lines?
-
Had an accident that makes me use crutches. Will that affect my new job?
-
Add and enable/disable Windows Firewall rules with Python
-
Is no religion a bad thing?
site design / logo © 2019 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0 with attribution required. rev 2019.1.9.32595