Git tips and tricks

<p>git rebase --interactive 8bf4b651207c8e60abf3822a276868942f1efe7a</p>

<p>git commit --amend --author="Suchi Garg &lt;suchi@axelerant.com&gt;"</p>

<p>git rebase --continue</p>

<p>Problem - squash commits</p>

<p>----------------------------------------</p>

<p>Suppose a branch has 3 commits and you want to squash all of them in one.</p>

<p class="p1">git rebase -i master</p>

<p>Your editor will open with a file like</p>

<p>pick fda59df commit 1<br />
pick x536897 commit 2<br />
pick c01a668 commit 3</p>

<p>&nbsp;</p>

<p>Each line represents a commit (in chronological order, the latest commit will be at the bottom).</p>

<p>To transform all these commits into a single one, change the file to this:</p>

<p>pick fda59df commit 1<br />
squash x536897 commit 2<br />
squash c01a668 commit 3</p>

<p><br />
This means, you take the first commit, and squash the following onto it. If you remove a line, the corresponding commit is actually really lost. Don't bother changing the commit messages because they are ignored. After saving the squash settings, your editor will open once more to ask for a commit message for the squashed commit.</p>

<p>---------------------</p>

<p>With the remote branches in hand, you now need to check out the branch you are interested in, giving you a local working copy:</p>

<p>git checkout -b test origin/test</p>

<p>&nbsp;</p>

<p>delete a remote branch</p>

<p>git push origin --delete WIZ-7488-Article-Theming</p>

<p>&nbsp;</p>

<p>Create a patch file using git diff:</p>

<p>git diff --no-prefix --color=never &gt; patchfile</p>

<p>------------------------</p>

<p>Problem - two repositories need to be merged. A &nbsp;and B are 2 repos, B has latest code -&gt; all code in B master need to be merged in A master</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<ol>
    <li>git clone A.git</li>
    <li>git remote add B B.git</li>
    <li>git fetch B</li>
    <li>git checkout -b masterB b/master</li>
    <li>git checkout masterB</li>
    <li>git merge -s ours master</li>
    <li>git checkout master</li>
    <li>git merge masterB</li>
    <li>git push origin master</li>
</ol>

<p>And you are done.</p>

<p>&nbsp;</p>
 

Tags