snipt

Ctrl+h for KB shortcuts
Notice: Snipt is moving away from free accounts on May 1st, 2014. Read more about the transition here.
#4789

Bash

move untracked files outside a git repository

git ls-files --others --exclude-standard -z | cpio -pmd0 ../untracked/
git clean -d

# git ls-files: print a
# * null-delimited (-z) list of 
# * untracked (--others)
# * non-ignored (--exclude-standard) files.
# cpio:
# * copy (-p)
# * files in a null-delimited list (-0)
# * create missing directories (-d)
# * preserve modification times (-m)
# git clean: remove untracked non-ignored files
# * and empty directories (-d)
# from the working tree
https://snipt.net/embed/22e3ac128b5eade2993fb533e6bd5ab5/
https://snipt.net/raw/22e3ac128b5eade2993fb533e6bd5ab5/
22e3ac128b5eade2993fb533e6bd5ab5
bash
Bash
15
2014-04-25T00:36:33
True
False
/api/public/snipt/4789/
move-untracked-files-outside-a-git-repository
<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> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a> <a href="#L-11">11</a> <a href="#L-12">12</a> <a href="#L-13">13</a> <a href="#L-14">14</a> <a href="#L-15">15</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>git ls-files --others --exclude-standard -z <span class="p">|</span> cpio -pmd0 ../untracked/ </span><span id="L-2"><a name="L-2"></a>git clean -d </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c"># git ls-files: print a</span> </span><span id="L-5"><a name="L-5"></a><span class="c"># * null-delimited (-z) list of </span> </span><span id="L-6"><a name="L-6"></a><span class="c"># * untracked (--others)</span> </span><span id="L-7"><a name="L-7"></a><span class="c"># * non-ignored (--exclude-standard) files.</span> </span><span id="L-8"><a name="L-8"></a><span class="c"># cpio:</span> </span><span id="L-9"><a name="L-9"></a><span class="c"># * copy (-p)</span> </span><span id="L-10"><a name="L-10"></a><span class="c"># * files in a null-delimited list (-0)</span> </span><span id="L-11"><a name="L-11"></a><span class="c"># * create missing directories (-d)</span> </span><span id="L-12"><a name="L-12"></a><span class="c"># * preserve modification times (-m)</span> </span><span id="L-13"><a name="L-13"></a><span class="c"># git clean: remove untracked non-ignored files</span> </span><span id="L-14"><a name="L-14"></a><span class="c"># * and empty directories (-d)</span> </span><span id="L-15"><a name="L-15"></a><span class="c"># from the working tree</span> </span></pre></div> </td></tr></table>
bash, git