{"id":115,"date":"2019-07-08T18:58:52","date_gmt":"2019-07-08T18:58:52","guid":{"rendered":"https:\/\/openapex.org\/spaces\/software\/?p=115"},"modified":"2023-01-03T18:56:48","modified_gmt":"2023-01-03T13:26:48","slug":"change-author-or-message-of-git-commit-after-push","status":"publish","type":"post","link":"https:\/\/mutesoft.com\/spaces\/software\/change-author-or-message-of-git-commit-after-push.html","title":{"rendered":"Change Author and Commit Message Before or After Push to Git"},"content":{"rendered":"\n<figure class=\"wp-block-image aligncenter size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/git-e1672746066670.png\" alt=\"Git\"\/><figcaption class=\"wp-element-caption\">Git<\/figcaption><\/figure>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\"><p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<\/div><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/mutesoft.com\/spaces\/software\/change-author-or-message-of-git-commit-after-push.html\/#1_Context\" >1. Context<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/mutesoft.com\/spaces\/software\/change-author-or-message-of-git-commit-after-push.html\/#2_Commit_Is_Not_Yet_Pushed\" >2. Commit Is Not Yet Pushed<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/mutesoft.com\/spaces\/software\/change-author-or-message-of-git-commit-after-push.html\/#3_Commit_Is_Already_Pushed\" >3. Commit Is Already Pushed<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/mutesoft.com\/spaces\/software\/change-author-or-message-of-git-commit-after-push.html\/#4_Conclusion\" >4. Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"1-context\"><span class=\"ez-toc-section\" id=\"1_Context\"><\/span><strong>1. Context<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>After committing a change, you realized that either the author is not appearing correctly or the commit message needs a change. There are two likely scenarios and in each scenario, we&#8217;ll explore how to change the commit metadata:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You haven&#8217;t pushed the commit yet<\/li>\n\n\n\n<li>You already have pushed the commit to the remote branch<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2-commit-is-not-yet-pushed\"><span class=\"ez-toc-section\" id=\"2_Commit_Is_Not_Yet_Pushed\"><\/span><strong>2. Commit Is Not Yet Pushed<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you have not pushed the commit to the remote branch yet, do not worry. Use <code>amend<\/code> option to change the last commit. You may include or exclude files of the last commit or just change the metadata such as author, message, etc. If you want to include additional files, ensure to stage the files before amending.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Change author and commit message\ngit commit --amend --author=\"Author Name &lt;author.email@email.com>\"<\/pre>\n\n\n\n<p>It opens up an editor where you can change the metadata such as author name, author email, commit message, etc.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"301\" src=\"https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/Screenshot-2022-02-18-at-3.07.55-AM-1024x301.png\" alt=\"Editor to change the commit message\" class=\"wp-image-1060\" srcset=\"https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/Screenshot-2022-02-18-at-3.07.55-AM-1024x301.png 1024w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/Screenshot-2022-02-18-at-3.07.55-AM-300x88.png 300w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/Screenshot-2022-02-18-at-3.07.55-AM-768x226.png 768w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/Screenshot-2022-02-18-at-3.07.55-AM-1536x452.png 1536w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/Screenshot-2022-02-18-at-3.07.55-AM-500x147.png 500w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/Screenshot-2022-02-18-at-3.07.55-AM-800x236.png 800w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/Screenshot-2022-02-18-at-3.07.55-AM-1280x377.png 1280w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/Screenshot-2022-02-18-at-3.07.55-AM.png 1644w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Editor to change the commit message<\/figcaption><\/figure>\n\n\n\n<p>After your change, save and close the editor. In order to confirm whether <code>Git<\/code> applied your changes correctly, execute the following commands:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Lists past commits. Check the metadata of the topmost one.\ngit log\n\n# Copy the commit id from the topmost one from git log to see the changes\ngit show &lt;commit_id>><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3-commit-is-already-pushed\"><span class=\"ez-toc-section\" id=\"3_Commit_Is_Already_Pushed\"><\/span><strong>3. Commit Is Already Pushed<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In case you have already pushed the commit to the remote branch, still do not worry. You can still change the commit metadata using an interactive rebase. Explore the commit history of the remote branch and note down the previous commit id of the target commit, for which you are going to change the metadata. Use the <code>rebase<\/code> command in interactive mode supplying the previous commit id.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Rebase in interactive mode. Id of the previous commit\ngit rebase -i &lt;commit_id><\/pre>\n\n\n\n<p>It opens an editor listing all subsequent commits with a set of commands, like below:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pick e9b09e1 Commit description\npick ef509e1 Commit description\n\n# Rebase ef507a8..e9b09e1 onto ef507a8 (1 command)\n#\n# Commands:\n# p, pick &lt;commit> = use commit\n# r, reword &lt;commit> = use commit, but edit the commit message\n# e, edit &lt;commit> = use commit, but stop for amending\n# s, squash &lt;commit> = use commit, but meld into previous commit\n# f, fixup &lt;commit> = like \"squash\", but discard this commit's log message\n# x, exec &lt;command> = run command (the rest of the line) using shell\n# d, drop &lt;commit> = remove commit\n............<\/pre>\n\n\n\n<p>Change the <code>pick<\/code> command with the desired action, save and close the editor. If you want to change multiple commits, for each commit, change the command appropriately. For amending a commit, use the <code>edit<\/code> command, for dropping a commit, use <code>drop<\/code> command, for changing just the commit message, use <code>reword<\/code> command, and so on. Git lists all the commands at the bottom with descriptions.<\/p>\n\n\n\n<p>Execute with <code>amend<\/code> options to change metadata such as author name, author email id etc. and then <code>continue<\/code> the <code>rebase<\/code> operation.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Change author and commit message\ngit commit --amend --author=\"Author Name &lt;author.email@email.com>\"\n\n# Continue the rebase, amend the next commit and again continue\ngit rebase --continue<\/pre>\n\n\n\n<p>Finally, submit all the changes using the force flag.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Force push all the modifications\ngit push --force-with-lease<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4-conclusion\"><span class=\"ez-toc-section\" id=\"4_Conclusion\"><\/span><strong>4. Conclusion<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Git interactive rebase is a powerful tool. It allows you to change almost everything in git history. Use it with utmost care.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After committing a change, you realized that either the author is not appearing correctly or the commit message needs a change. There are two likely scenarios and in each scenario, we&#8217;ll explore how to change the commit metadata.<\/p>\n","protected":false},"author":2,"featured_media":1053,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"After committing a change, you realized that either the author is not appearing correctly or the commit message needs a change. There are two likely scenarios and in each scenario, we&#039;ll explore how to change the commit metadata.","_seopress_robots_index":"","_vp_format_video_url":"","_vp_image_focal_point":[],"footnotes":""},"categories":[32],"tags":[31],"class_list":["post-115","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tools","tag-git"],"_links":{"self":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/comments?post=115"}],"version-history":[{"count":24,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/115\/revisions"}],"predecessor-version":[{"id":1373,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/115\/revisions\/1373"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/media\/1053"}],"wp:attachment":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/media?parent=115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/categories?post=115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/tags?post=115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}