Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Text only

How to compare two local branches in Git

1
2
3
4
5
git diff local_branch1 local_branch2

Example:

git diff dev master
https://snipt.net/embed/e7f8dfa6ed2929f9bfaaf6c325c27425/
https://snipt.net/raw/e7f8dfa6ed2929f9bfaaf6c325c27425/
e7f8dfa6ed2929f9bfaaf6c325c27425
text
Text only
5
2016-12-02T06:34:01
True
False
False
Jul 23, 2016 at 07:05 PM
/api/public/snipt/147454/
how-to-compare-two-local-branches-in-git
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>git diff local_branch1 local_branch2 </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>Example: </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>git diff dev master </span></pre></div> </td></tr></table>
git

Text only

How to track a remote branch from a local branch in Git

1
2
3
4
5
git branch -u remote_respository/remote_branch 

Example:

git branch -u origin/dev 
https://snipt.net/embed/99de4e113fdbbf03564dd96410e27750/
https://snipt.net/raw/99de4e113fdbbf03564dd96410e27750/
99de4e113fdbbf03564dd96410e27750
text
Text only
5
2016-12-02T06:34:04
True
False
False
/api/public/snipt/147453/
git-command-reference
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>git branch -u remote_respository/remote_branch </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>Example: </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>git branch -u origin/dev </span></pre></div> </td></tr></table>
git

Markdown

.gitignore - ignore without deleting

Instead of .gitignore, you can update local git repository by running following command: git update-index --assume-unchanged <file> In this case a file is being tracked in the origin repo. You can modify it in your local repo and git will never mark it as changed. Read more at http://blog.pagebakers.nl/2009/01/29/git-ignoring-changes-in-tracked-files/

https://snipt.net/embed/dd20d40fb0528609c2f27c405159be4a/
https://snipt.net/raw/dd20d40fb0528609c2f27c405159be4a/
dd20d40fb0528609c2f27c405159be4a
markdown
Markdown
7
2016-12-02T06:34:06
True
False
False
May 04, 2016 at 06:35 PM
/api/public/snipt/146112/
gitignore-ignore-without-deleting
<p>Instead of .gitignore, you can update local git repository by running following command: <code> git update-index --assume-unchanged &lt;file&gt; </code> In this case a file is being tracked in the origin repo. You can modify it in your local repo and git will never mark it as changed. Read more at http://blog.pagebakers.nl/2009/01/29/git-ignoring-changes-in-tracked-files/</p>
git

Bash

拉回git 遠端branch

git checkout --track -b foobar origin/foobar 
# 將遠端的 branch checkout 回來並建立一個新的 local branch,加上 --track 表示你之後還要pull、push回去,所以請 Git 記住對應關係。
https://snipt.net/embed/e29c7918ceec0898b25249475481b39e/
https://snipt.net/raw/e29c7918ceec0898b25249475481b39e/
e29c7918ceec0898b25249475481b39e
bash
Bash
2
2016-12-02T06:34:12
True
False
False
Mar 09, 2016 at 09:01 PM
/api/public/snipt/144644/
git-branch
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>git checkout --track -b foobar origin/foobar </span><span id="L-2"><a name="L-2"></a><span class="c1"># 將遠端的 branch checkout 回來並建立一個新的 local branch,加上 --track 表示你之後還要pull、push回去,所以請 Git 記住對應關係。</span> </span></pre></div> </td></tr></table>
git, sh

Bash

View Commit Differences Between Two Branches in Git

git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative BRANCHNAME..OTHERBRANCHNAME
https://snipt.net/embed/7a2b4368acd071c9295f220e4009deb9/
https://snipt.net/raw/7a2b4368acd071c9295f220e4009deb9/
7a2b4368acd071c9295f220e4009deb9
bash
Bash
1
2016-12-02T06:34:21
True
False
False
Jan 07, 2016 at 04:21 PM
/api/public/snipt/143460/
view-commit-differences-between-two-branches-in-git
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>git log --graph --pretty<span class="o">=</span>format:<span class="s1">&#39;%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset&#39;</span> --abbrev-commit --date<span class="o">=</span>relative BRANCHNAME..OTHERBRANCHNAME </span></pre></div> </td></tr></table>
branches, commits, diff, git

Text only

Git - Remove local changes & pull from repo

git fetch --all
git reset --hard origin/master
https://snipt.net/embed/7d683e6531c2f892b0c388aca4f94c60/
https://snipt.net/raw/7d683e6531c2f892b0c388aca4f94c60/
7d683e6531c2f892b0c388aca4f94c60
text
Text only
2
2016-12-02T15:15:34
True
False
False
Oct 04, 2015 at 06:14 PM
/api/public/snipt/141491/
git-remove-local-changes-pull-from-repo
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>git fetch --all </span><span id="L-2"><a name="L-2"></a>git reset --hard origin/master </span></pre></div> </td></tr></table>
changes, git, remove

Text only

git - remove file tracking

git rm --cached FILENAME
https://snipt.net/embed/b95f9e34e8e024efa716289d976d771e/
https://snipt.net/raw/b95f9e34e8e024efa716289d976d771e/
b95f9e34e8e024efa716289d976d771e
text
Text only
1
2016-12-02T16:02:42
True
False
False
Oct 04, 2015 at 04:35 PM
/api/public/snipt/141490/
git-remove-file-tracking
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>git rm --cached FILENAME </span></pre></div> </td></tr></table>
git, remove, tracking
Copyrighted, illegal, or inappropriate content? Email [email protected].