snipt

Ctrl+h for KB shortcuts

Bash

Remove untracked files from a working copy

git clean -f -d
https://snipt.net/embed/2475339aabf270d85c75a522139069b0/
/raw/2475339aabf270d85c75a522139069b0/
2475339aabf270d85c75a522139069b0
bash
Bash
1
2019-06-30T14:13:16
True
False
False
Jan 07, 2014 at 09:45 PM
/api/public/snipt/104324/
remove-untracked-files-from-a-working-copy
<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 clean -f -d </span></pre></div> </td></tr></table>
git

Bash

Merge with --ours and --theirs

1
2
3
4
" Keep the current branch version
git checkout --ours <file_path>
" Keep the pulled version
git checkout --theirs <file_path>
https://snipt.net/embed/f0bc8d8c5eacfd5b08b4fbfcef1b3353/
/raw/f0bc8d8c5eacfd5b08b4fbfcef1b3353/
f0bc8d8c5eacfd5b08b4fbfcef1b3353
bash
Bash
4
2019-07-10T09:55:14
True
False
False
Jul 23, 2013 at 10:05 PM
/api/public/snipt/69258/
merge-with-ours-and-theirs
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="s2">&quot; Keep the current branch version</span> </span><span id="L-2"><a name="L-2"></a><span class="s2">git checkout --ours &lt;file_path&gt;</span> </span><span id="L-3"><a name="L-3"></a><span class="s2">&quot;</span> Keep the pulled version </span><span id="L-4"><a name="L-4"></a>git checkout --theirs &lt;file_path&gt; </span></pre></div> </td></tr></table>
git

Bash

Revert to the Previous Commit

$ git reset --hard HEAD^
https://snipt.net/embed/5800d1ecc4aed091ec2751c8be86b5ea/
/raw/5800d1ecc4aed091ec2751c8be86b5ea/
5800d1ecc4aed091ec2751c8be86b5ea
bash
Bash
1
2019-06-25T12:14:58
True
False
False
Jul 23, 2013 at 09:53 PM
/api/public/snipt/69257/
revert-to-the-previous-commit
<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 reset --hard HEAD^ </span></pre></div> </td></tr></table>
git

Bash

Ignore versioned files

1
2
3
4
git update-index --assume-unchanged <files>

# To get back to tracking the file changes
git update-index --no-assume-unchanged <files>
https://snipt.net/embed/22fc3da935328de88495b701221b5e54/
/raw/22fc3da935328de88495b701221b5e54/
22fc3da935328de88495b701221b5e54
bash
Bash
4
2019-06-29T23:45:00
True
False
False
Apr 01, 2013 at 02:59 AM
/api/public/snipt/58622/
ignore-versioned-files
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>git update-index --assume-unchanged &lt;files&gt; </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="c1"># To get back to tracking the file changes</span> </span><span id="L-4"><a name="L-4"></a>git update-index --no-assume-unchanged &lt;files&gt; </span></pre></div> </td></tr></table>
git

Bash

Restore a deleted file

1
2
3
4
5
6
git rev-list -n 1 HEAD -- <file_path>
git checkout <deleting_commit>^ -- <file_path>

OR

git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"
https://snipt.net/embed/cdf86d3351fb49f73848f7051e2fa0d5/
/raw/cdf86d3351fb49f73848f7051e2fa0d5/
cdf86d3351fb49f73848f7051e2fa0d5
bash
Bash
6
2019-07-03T03:29:36
True
False
False
Jan 16, 2013 at 07:00 AM
/api/public/snipt/53829/
restore-a-deleted-file
<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> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>git rev-list -n <span class="m">1</span> HEAD -- &lt;file_path&gt; </span><span id="L-2"><a name="L-2"></a>git checkout &lt;deleting_commit&gt;^ -- &lt;file_path&gt; </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a>OR </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a>git checkout <span class="k">$(</span>git rev-list -n <span class="m">1</span> HEAD -- <span class="s2">&quot;</span><span class="nv">$file</span><span class="s2">&quot;</span><span class="k">)</span>^ -- <span class="s2">&quot;</span><span class="nv">$file</span><span class="s2">&quot;</span> </span></pre></div> </td></tr></table>
git

Bash

Create a tag

git tag -a <tag_name>
git push --tags			
https://snipt.net/embed/f7b73c596330a89302fa9e9d3806c36c/
/raw/f7b73c596330a89302fa9e9d3806c36c/
f7b73c596330a89302fa9e9d3806c36c
bash
Bash
2
2019-07-10T03:53:48
True
False
False
/api/public/snipt/47769/
create-a-tag
<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 tag -a &lt;tag_name&gt; </span><span id="L-2"><a name="L-2"></a>git push --tags </span></pre></div> </td></tr></table>
git

Bash Session

Push a local branch to a remote different branch

git push remote local_branch:remote_branch
https://snipt.net/embed/c227d744594e491495483cb192263a01/
/raw/c227d744594e491495483cb192263a01/
c227d744594e491495483cb192263a01
console
Bash Session
1
2019-06-06T21:57:51
True
False
False
/api/public/snipt/43162/
push-a-local-branch-to-a-remote-different-branch
<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><span class="go">git push remote local_branch:remote_branch</span> </span></pre></div> </td></tr></table>
git

Bash

Revert uncommitted changes

$ git reset --hard HEAD
https://snipt.net/embed/f29818839e2b75f8f8b4faf0d251ffde/
/raw/f29818839e2b75f8f8b4faf0d251ffde/
f29818839e2b75f8f8b4faf0d251ffde
bash
Bash
1
2019-07-02T14:38:38
True
False
False
/api/public/snipt/36547/
revert-uncommitted-changes
<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 reset --hard HEAD </span></pre></div> </td></tr></table>
git

Bash

Create a branch based on the current HEAD

$ git checkout -b <branch_name>
https://snipt.net/embed/3cb8d753b8bfc8f648d678f732fdcf02/
/raw/3cb8d753b8bfc8f648d678f732fdcf02/
3cb8d753b8bfc8f648d678f732fdcf02
bash
Bash
1
2019-07-14T13:45:40
True
False
False
/api/public/snipt/33489/
create-a-branch-based-on-the-current-head
<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 checkout -b &lt;branch_name&gt; </span></pre></div> </td></tr></table>
git

Bash

List commit objects

$ git rev-list <branch_1>..<branch_2>
https://snipt.net/embed/7ee7858b5e2ba989588e168276dd6f18/
/raw/7ee7858b5e2ba989588e168276dd6f18/
7ee7858b5e2ba989588e168276dd6f18
bash
Bash
1
2019-07-11T05:58:34
True
False
False
/api/public/snipt/33488/
list-commit-objects
<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 rev-list &lt;branch_1&gt;..&lt;branch_2&gt; </span></pre></div> </td></tr></table>
git