<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>interactive rebase &#8211; CodePills.com</title>
	<atom:link href="https://codepills.com/tag/interactive-rebase/feed/" rel="self" type="application/rss+xml" />
	<link>https://codepills.com</link>
	<description>Helping you make a better code</description>
	<lastBuildDate>Mon, 12 Jul 2021 07:51:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>How to set custom configuration for your local Git project repository</title>
		<link>https://codepills.com/how-to-set-custom-configuration-for-your-local-git-project-repository/</link>
					<comments>https://codepills.com/how-to-set-custom-configuration-for-your-local-git-project-repository/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Thu, 01 Jul 2021 09:14:05 +0000</pubDate>
				<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[IntelliJ]]></category>
		<category><![CDATA[interactive rebase]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1243</guid>

					<description><![CDATA[Suppose you do not want to have the same configuration for your local repository as you have your global Git settings. Or you need to fix identity information for commits that are already made in Git commit history. In that case, this article will show you a few Git commands on how to set up the custom configuration for your local Git repository or how to fix past mistakes. <a href="https://codepills.com/how-to-set-custom-configuration-for-your-local-git-project-repository/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>Suppose you do not want to have the same configuration for your local repository as you have your global Git settings. Or you need to fix identity information for commits that are already made in Git commit history. In that case, this article will show you a few Git commands on how to set up the custom configuration for your local Git repository or how to fix past mistakes.</p>
<p><span id="more-1243"></span></p>
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#change_future_commits_author">Change Future Commits Author</a></li>
<ul>
<li><a href="#git_config_check">Git Config Check</a></li>
<li><a href="#git_global_configuration">Git Global Configuration</a></li>
<li><a href="#git_local_configuration">Git Local Configuration</a></li>
<li><a href="#author_identity_for_the_next_commit">Author Identity For the Next Commit</a></li>
</ul>
<li><a href="#change_past_commits_author">Change Past Commits Author</a></li>
<ul>
<li><a href="#git_ammend_with_author_flag">Git Ammend With Author Flag</a></li>
<li><a href="#git_interactive_rebase">Git Interactive Rebase</a></li>
<li><a href="#git_filter-branch">Git filter-branch Command</a></li>
</ul>
<li><a href="#conclusion">Conclusion</a></li>
</ul>
<h2 id="introduction">Introduction</h2>
<p>There are two different needs in the request of changing author for your commits. Let&#8217;s make clear what are you really looking for:</p>
<ul>
<li>a) Either you want to change the author <b>before</b> making commit.</li>
<li>b) Or you want to change the author <b>after</b> you have made commit.</li>
</ul>
<p>In this article, we will look at both ways how to change the commit&#8217;s author identity.</p>
<h2 id="change_future_commits_author">Change Future Commits Author</h2>
<p>There are three different ways how to change identity for your Git committer. All the procedures only affect future commits and not the past commits made in the development line of your repository (commit history).</p>
<h3 id="git_config_check">Git Config Check</h3>
<p>Just a quick tip. To confirm your settings for global and local configuration you can type command:</p>
<pre><code class="language-bash">git config --list</code></pre>
<p><code>git config --list</code> will show global system git settings. If you run it inside a repository, it will also attach and show you the local configuration.</p>
<p>However, using following command might be more clearer:</p>
<pre><code class="language-bash">git config --list --show-origin</code></pre>
<p><code>git config --list --show-origin</code> command does all what <code>git config --list</code> does. Git command also attaches a path to the origin file of each config item in the list. Arguably, the attached path makes the settings look more understandable, and you can better connect items and their values for local and global Git settings.</p>
<h3 id="git_global_configuration">Git Global Configuration</h3>
<p>If you want to change your username and email by default for all project on your machine, edit global configuration settings. You can run the <code>git config</code> command with <code>--global</code> flag that will override your default Git settings and apply for all the future commits in your repositories. Git command for it looks like this:</p>
<pre><code class="language-bash">git config --global user.name "FIRST_NAME LAST_NAME"
git config --global user.email "EMAIL@example.com"</code></pre>
<h3 id="git_local_configuration">Git Local Configuration</h3>
<p>However, if you want to change your username and email only for single project, go to your repository and make git config adjustment like this:</p>
<pre><code class="language-bash">git config --local user.name "FIRST_NAME LAST_NAME"
git config --local user.email "EMAIL@example.com"</code></pre>
<p>Simply omit the <code>--global</code> flag and replace it with <code>--local</code> flag. <code>git config --local</code> makes the custom configuration valid only in the repository you made a change.</p>
<h3 id="author_identity_for_the_next_commit">Author Identity For the Next Commit</h3>
<p>There is at least one last way how to temporary influence the author identity of the commit. Just right before making the commit, add to <code>commit</code> command <code>--author</code> flag. When making the commit, you can override even local settings.</p>
<pre><code class="language-bash">git commit --author="FIRST_NAME LAST_NAME <EMAIL@example.com>"</code></pre>
<h2 id="change_past_commits_author">Change Past Commits Author</h2>
<p>Changing past commit authors in Git repositories is not so straightforward as it is for future ones. The issue lies in the fundamental idea of Git &#8211; its distributed asynchronous nature. You should be aware of one simple fact that you might cause a massive problem with synchronization if you work on the project with many team members.</p>
<p><strong>When you change Git commit author identity, you create an entirely new commit with a new hash; you are rewriting commit history and development branch.</strong> And while for a single individual repository user, this might not be a problem, for big teams, this might be a cause of enormous evil.</p>
<p>Therefore, let me give you a piece of good advice: if you are working in a team, a change in Git commit history should be adequately communicated with the rest of the team. It might happen that other team members already based their work on the existing commits, and additional changes would cause huge synchronization problems. Communicate with your team if you feel that commits might be already used as the base for other people work. Eventually, for good or bad, it might be possible even to avoid changing commit author identity, and either do rollback commit with new commit with correct author commit or, better, leave the commit history as it is. Commit change is much more critical in the long term as a person who made it (empirical experience &#8211; people come and go from teams, code stays forever).</p>
<h3 id="git_ammend_with_author_flag">Git Ammend With Author Flag</h3>
<p><code>git ammend</code> command is used to patch last commit in Git&#8217;s commit history. By attaching <code>--author</code> flag to <code>git ammend</code> command you can effectively rewrite commit author identity for the last commit in commit history.</p>
<h3 id="git_interactive_rebase">Git Interactive Rebase</h3>
<p><strong>Interactive rebase</strong> is a powerful feature of Git that allows you to edit Git commit history very effectively.</p>
<p>However, <strong>be careful with interactive rebase</strong>, it might shoot you in the foot if you will be not careful! Any changes made will affect your Git commit history. I would recommend to study deeper official Git documentation for <strong>interactive rebase</strong> before making any changes with it over console [<a href="https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages" title="" target="_blank" rel="nofollow noopener">7.6 Git Tools &#8211; Rewriting History</a>]. Otherwise I can really recommend using <strong>interactive rebase</strong> with IDE tools such as <strong>IntelliJ</strong>.</p>
<p>First step, you need to find commit you consider as base for your <strong>interactive rebase</strong>. Provide to git command commit&#8217;s hash like this:</p>
<pre><code class="language-bash">$ git rebase -i -p 9be2477a</code></pre>
<p><code>git rebase</code> command will open the interactive editor in which you need to mark all the commits you want to change. Selected commits will be marked with the red keyword &#8220;edit&#8221;.</p>
<pre><code class="language-bash"><span style="color: red">edit</span> 87bee32a Added new tests
<span style="color: red">edit</span> 1be09dcb Merge branch with hotfix for DJ-1041
<span style="color: red">edit</span> 9be2477a Change title tag for homepage
<span style="color: red">edit</span> c427697c Add images support in gallery</code></pre>
<p>Git will now walk you through each commit. You will have a chance to change every commit individually:</p>
<pre><code class="language-bash">Stopped at 1be09dcb... Merge branch with hotfix for DJ-1041
You can amend the commit now, with

    git commit --amend

Once you are satisfied with your changes, run

    git rebase --continue</code></pre>
<p>Now is your chance to rewrite the commit author identity. Either you will use <code>--amend</code> with <code>--author</code> flag. Or you will continue to next commit in edit mode until you have edited all commits which were marked for edit</p>
<pre><code class="language-bash">$ git commit --amend --author="FIRST_NAME LAST_NAME <EMAIL@example.com>" --no-edit
$ git rebase --continue</code></pre>
<h3 id="git_filter-branch">Git filter-branch</h3>
<p>Last option is to use Git <code>filter-branch</code> command. <code>filter-branch</code> will allow you to go through a large chunk of  commits with the help of simple script. Let us show you a simple script:</p>
<pre><code class="language-bash">$ git filter-branch --env-filter '
OLD_COMMITTER_EMAIL="OLD_EMAIL@example.com"
NEW_COMMITTER_NAME="FIRST_NAME LAST_NAME"
NEW_COMMITTER_EMAIL="NEW_EMAIL@example.com"

if [ "$GIT_COMMITTER_EMAIL" = "$OLD_COMMITTER_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$NEW_COMMITTER_NAME"
    export GIT_COMMITTER_EMAIL="$NEW_COMMITTER_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_COMMITTER_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$NEW_COMMITTER_NAME"
    export GIT_AUTHOR_EMAIL="$NEW_COMMITTER_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags</code></pre>
<p>However, same as with <strong>interactive rebase</strong>, it is necessary to be aware that by using <code>filter-branch</code>, you will create entirely new sort of commits and change Git commit history. The new commit history might have severe consequences when synchronizing with your team, so you should do this preferably only on repositories that haven&#8217;t been published or shared.</p>
<h2 id="conclusion">Conclusion</h2>
<p>In summary, we divided the methods of changing the commit author identity into two different approaches based on the commit stage. We showed three different ways to change the author information before making a commit, and we explained another three ways to change the author information after making a commit.</p>
<p>Did you find commands easy? Do you have your trick or know another way <u>how to change global and local Git settings</u>? Let us know in the comments below the article. We would like to hear your ideas and stories.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-set-custom-configuration-for-your-local-git-project-repository/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
