![]() ![]() see the "Environment Variables" section of the git manual page. ![]() Also note that you can use environment variables to change the name of the author, committer, dates, etc. The manual page includes several examples to get you started. If you're okay with that and think it's worth it then you should check out git filter-branch. If you still need to use git filter-branch, please carefully read SAFETY (and PERFORMANCE) to learn about the land mines of filter-branch, and then vigilantly avoid as many of the hazards listed there as reasonably possible.Ĭhanging the author (or committer) would require rewriting all of the history. Please use an alternative history filtering tool such as git filter-repo. These safety and performance issues cannot be backward compatibly fixed and as such, its use is not recommended. Git filter-branch has a plethora of pitfalls that can produce non-obvious manglings of the intended history rewrite (and can leave you with little time to investigate such problems since it has such abysmal performance). This answer uses git-filter-branch, for which the docs now give this warning: Note that -p has serious issues and is now deprecated. Just amend the commit: git commit -amend -no-edit -reset-authorĮntire project history git rebase -r -root -exec "git commit -amend -no-edit -reset-author" If you just want to change the most recent commit, a rebase is not necessary. Note that doing so will not update the committer - just the author. If you did not want to change that config, you can use -author "New Author Name " instead of -reset-author. This will change both the committer and the author to your user.name/ user.email configuration. If you also want to change your first commit (also called the 'root' commit), you will have to add -root to the rebase call. exec will run the git commit step after each commit is rewritten (as if you ran git commit & git rebase -continue repeatedly). ![]() exec 'git commit -amend -no-edit -reset-author' To rewrite metadata for a range of commits using a rebase, do git rebase -r \ This is optional, but it will also make sure to reset the committer name, too, assuming that's what you need. Using Rebaseįirst, if you haven't already done so, you will likely want to fix your name in git-config: git config -global user.name "New Author Name" If you only want to fix the spelling of a name or update an old email, Git lets you do this without rewriting history using. Let's edit the commit message by modifying the first line to “Adding file2”, saving the file, and closing the editor.NOTE: This answer changes SHA1s, so take care when using it on a branch that has already been pushed. The comments on the following lines describe how the reword operation will work. The first line contains the commit message: Ading file2 Since we told Git to reword the first commit, it'll reopen the text editor with the contents of the first commit. Git will now process the rebase commands, prompting us when it needs our interaction. So let's save our file and close the text editor, which lets Git know we have finished our rebasing instructions. Now, we haven't changed the commit message just yet. If we wanted to change both messages in a single rebase, we could simply change the commands on both lines to reword. Let's change the first line to use the reword command instead of the pick command we'll leave pick for the second commit because we want to keep that message as it is: reword ffb7a68bf6 Ading file2 Note that, in this view, the commits are listed from the oldest to the most recent, as opposed to when we use git log. The two first lines in the editor contain the following text: pick ffb7a68bf6 Ading file2 ![]() Git's amend option only works with the latest commit, so we can't use that to fix the typo this time. Ading file2ġ file changed, 0 insertions(+), 0 deletions(-) Let's now add two new commits so that the typo does not exist in the most recent commit but in an older one: $ touch file2 ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |