mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
Complete git-ignore includes global.
Did a rebase merge from the old pull request #46 which we may close now. Yet it wasn't as simple as that in the end but all things have a resolve: Added 2 context type arguments to specify --local or --global. Refactored usage into functions te prevent duplication. Capable to view and append to both global gitignore as well as the .gitignore from the working folder. Supports all types of ignore patters including ! negated, comments as well as blank lines. Complete documentation including several examples.
This commit is contained in:
parent
8f4a17044d
commit
c749fdc54f
|
|
@ -1,15 +1,50 @@
|
|||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
function show_contents {
|
||||
test -f "$2" && echo "$1 gitignore: $2" && cat "$2"
|
||||
}
|
||||
|
||||
function show_global {
|
||||
show_contents Global `git config --global core.excludesfile`
|
||||
}
|
||||
|
||||
function add_global {
|
||||
add_patterns `git config --global core.excludesfile` "$@"
|
||||
}
|
||||
|
||||
function show_local {
|
||||
show_contents Local .gitignore
|
||||
}
|
||||
|
||||
function add_local {
|
||||
add_patterns .gitignore "$@"
|
||||
}
|
||||
|
||||
function add_patterns {
|
||||
echo "Adding pattern(s) to: $1"
|
||||
for pattern in "${@:2}"; do
|
||||
echo "... adding '$pattern'"
|
||||
(test -f "$1" && test "$pattern" && grep -q "$pattern" "$1") || echo "$pattern" >> "$1"
|
||||
done
|
||||
}
|
||||
|
||||
if test $# -eq 0; then
|
||||
test -f .gitignore && cat .gitignore
|
||||
if test -f `git config --global core.excludesfile`; then
|
||||
echo -e "\n# Global gitignore:\n"
|
||||
cat `git config --global core.excludesfile`
|
||||
fi
|
||||
show_global
|
||||
echo "---------------------------------"
|
||||
show_local
|
||||
else
|
||||
for pattern in $@; do
|
||||
echo "... adding '$pattern' to .gitignore"
|
||||
(test -f .gitignore && grep -q $pattern .gitignore) || echo $pattern >> .gitignore
|
||||
done
|
||||
case "$1" in
|
||||
-l|--local)
|
||||
test $# -gt 1 && add_local "${@:2}" && echo
|
||||
show_local
|
||||
;;
|
||||
-g|--global)
|
||||
test $# -gt 1 && add_global "${@:2}" && echo
|
||||
show_global
|
||||
;;
|
||||
*)
|
||||
add_local "$@"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
|
|
|||
151
man/git-ignore.1
151
man/git-ignore.1
|
|
@ -1,53 +1,168 @@
|
|||
.\" generated with Ronn/v0.7.3
|
||||
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
||||
.
|
||||
.TH "GIT\-IGNORE" "1" "March 2011" "" "Git Extras"
|
||||
.TH "GIT\-IGNORE" "1" "July 2012" "" ""
|
||||
.
|
||||
.SH "NAME"
|
||||
\fBgit\-ignore\fR \- Add \.gitignore patterns
|
||||
.
|
||||
.SH "SYNOPSIS"
|
||||
\fBgit\-ignore\fR [<pattern>\|\.\|\.\|\.]
|
||||
\fBgit\-ignore\fR [<context>] [<pattern> [<pattern>]\.\.\.]
|
||||
.
|
||||
.SH "DESCRIPTION"
|
||||
Adds the given _pattern_s to a gitignore file\.
|
||||
Adds the given _pattern_s to a \.gitignore file if it doesn\'t already exist\.
|
||||
.
|
||||
.SH "OPTIONS"
|
||||
<context>
|
||||
.
|
||||
.SH "EXAMPLES"
|
||||
To lazy to open up \fI\.gitignore\fR? me too! simply pass some patterns:
|
||||
.P
|
||||
\-l, \-\-local
|
||||
.
|
||||
.IP "" 4
|
||||
.P
|
||||
Sets the context to the \.gitignore file in the current working directory\. (default)
|
||||
.
|
||||
.nf
|
||||
|
||||
$ git ignore build "*\.o" "*\.log"
|
||||
\|\.\|\.\|\. added \'build\'
|
||||
\|\.\|\.\|\. added \'*\.o\'
|
||||
\|\.\|\.\|\. added \'*\.log\'
|
||||
.P
|
||||
\-g, \-\-global
|
||||
.
|
||||
.fi
|
||||
.P
|
||||
Sets the context to the global gitignore file fol the current user\.
|
||||
.
|
||||
.P
|
||||
<pattern>
|
||||
.
|
||||
.P
|
||||
A space delimited list of patterns to append to the file in context\.
|
||||
.
|
||||
.SS "PATTERN FORMAT"
|
||||
Pattern format as described in the git manual
|
||||
.
|
||||
.IP "\(bu" 4
|
||||
A blank line matches no files, so it can serve as a separator for readability\. To append a blank line use empty quotes ""\.
|
||||
.
|
||||
.IP "\(bu" 4
|
||||
A line starting with # serves as a comment\. For example, "# This is a comment"
|
||||
.
|
||||
.IP "\(bu" 4
|
||||
An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern will become included again\. If a negated pattern matches, this will override lower precedence patterns sources\. To use an exclamation ! as command line argument it is best placed between single quotes \'\'\. For example, \'!src\'
|
||||
.
|
||||
.IP "\(bu" 4
|
||||
If the pattern ends with a slash, it is removed for the purpose of the following description, but it would only find a match with a directory\. In other words, foo/ will match a directory foo and paths underneath it, but will not match a regular file or a symbolic link foo (this is consistent with the way how pathspec works in general in git)\.
|
||||
.
|
||||
.IP "\(bu" 4
|
||||
If the pattern does not contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the \.gitignore file (relative to the toplevel of the work tree if not from a \.gitignore file)\.
|
||||
.
|
||||
.IP "\(bu" 4
|
||||
Otherwise, git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname\. For example, "Documentation/*\.html" matches "Documentation/git\.html" but not "Documentation/ppc/ppc\.html" or "tools/perf/Documentation/perf\.html"\.
|
||||
.
|
||||
.IP "\(bu" 4
|
||||
A leading slash matches the beginning of the pathname\. For example, "/*\.c" matches "cat\-file\.c" but not "mozilla\-sha1/sha1\.c"\.
|
||||
.
|
||||
.IP "" 0
|
||||
.
|
||||
.P
|
||||
Running \fBgit\-ignore\fR without a pattern will display the current patterns:
|
||||
.SH "EXAMPLES"
|
||||
All arguments are optional so calling git\-ignore alone will display first the global then the local gitignore files:
|
||||
.
|
||||
.IP "" 4
|
||||
.
|
||||
.nf
|
||||
|
||||
$ git ignore
|
||||
build
|
||||
*\.o
|
||||
Global gitignore: /home/alice/\.gitignore
|
||||
# Numerous always\-ignore extensions
|
||||
*\.diff
|
||||
*\.err
|
||||
*\.orig
|
||||
*\.rej
|
||||
*\.swo
|
||||
*\.swp
|
||||
*\.vi
|
||||
*~
|
||||
*\.sass\-cache
|
||||
|
||||
# OS or Editor folders
|
||||
\.DS_Store
|
||||
\.Trashes
|
||||
\._*
|
||||
Thumbs\.db
|
||||
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
|
||||
Local gitignore: \.gitignore
|
||||
\.cache
|
||||
\.project
|
||||
\.settings
|
||||
\.tmproj
|
||||
nbproject
|
||||
.
|
||||
.fi
|
||||
.
|
||||
.IP "" 0
|
||||
.
|
||||
.P
|
||||
If you only want to see the global context use the \-\-global argument (for local use \-\-local):
|
||||
.
|
||||
.IP "" 4
|
||||
.
|
||||
.nf
|
||||
|
||||
$ git ignore
|
||||
Global gitignore: /home/alice/\.gitignore
|
||||
\.DS_Store
|
||||
\.Trashes
|
||||
\._*
|
||||
Thumbs\.db
|
||||
.
|
||||
.fi
|
||||
.
|
||||
.IP "" 0
|
||||
.
|
||||
.P
|
||||
To quickly append a new pattern to the default/local context simply:
|
||||
.
|
||||
.IP "" 4
|
||||
.
|
||||
.nf
|
||||
|
||||
$ git ignore *\.log
|
||||
Adding pattern(s) to: \.gitignore
|
||||
\.\.\. adding \'*\.log\'
|
||||
.
|
||||
.fi
|
||||
.
|
||||
.IP "" 0
|
||||
.
|
||||
.P
|
||||
You can now configure any patterns without ever using an editor, with a context and pattern arguments: The resulting configuration is also returned for your convenience\.
|
||||
.
|
||||
.IP "" 4
|
||||
.
|
||||
.nf
|
||||
|
||||
$ git ignore \-\-local "" "# Temporary files" *\.tmp "*\.log" tmp/* "" "# Files I\'d like to keep" \'!work\' ""
|
||||
Adding pattern(s) to: \.gitignore
|
||||
\.\.\. adding \'\'
|
||||
\.\.\. adding \'# Temporary files\'
|
||||
\.\.\. adding \'index\.tmp\'
|
||||
\.\.\. adding \'*\.log\'
|
||||
\.\.\. adding \'tmp/*\'
|
||||
\.\.\. adding \'\'
|
||||
\.\.\. adding \'# Files I\'d like to keep\'
|
||||
\.\.\. adding \'!work\'
|
||||
\.\.\. adding \'\'
|
||||
|
||||
Local gitignore: \.gitignore
|
||||
|
||||
# Temporary files
|
||||
index\.tmp
|
||||
*\.log
|
||||
|
||||
# Files I\'d like to keep
|
||||
!work
|
||||
.
|
||||
.fi
|
||||
.
|
||||
.IP "" 0
|
||||
.
|
||||
.SH "AUTHOR"
|
||||
Written by Tj Holowaychuk <\fItj@vision\-media\.ca\fR>
|
||||
Written by Tj Holowaychuk <\fItj@vision\-media\.ca\fR> and Tema Bolshakov <\fItweekane@gmail\.com\fR> and Nick Lombard <\fIgithub@jigsoft\.co\.za\fR>
|
||||
.
|
||||
.SH "REPORTING BUGS"
|
||||
<\fIhttp://github\.com/visionmedia/git\-extras/issues\fR>
|
||||
|
|
|
|||
|
|
@ -61,11 +61,11 @@
|
|||
<a href="#AUTHOR">AUTHOR</a>
|
||||
<a href="#REPORTING-BUGS">REPORTING BUGS</a>
|
||||
<a href="#SEE-ALSO">SEE ALSO</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ol class='man-decor man-head man head'>
|
||||
<li class='tl'>git-ignore(1)</li>
|
||||
<li class='tc'>Git Extras</li>
|
||||
<li class='tc'></li>
|
||||
<li class='tr'>git-ignore(1)</li>
|
||||
</ol>
|
||||
|
||||
|
|
@ -76,35 +76,120 @@
|
|||
|
||||
<h2 id="SYNOPSIS">SYNOPSIS</h2>
|
||||
|
||||
<p><code>git-ignore</code> [<pattern>...]</p>
|
||||
<p><code>git-ignore</code> [<context>] [<pattern> [<pattern>]...]</p>
|
||||
|
||||
<h2 id="DESCRIPTION">DESCRIPTION</h2>
|
||||
|
||||
<p>Adds the given _pattern_s to a gitignore file.</p>
|
||||
<p>Adds the given _pattern_s to a .gitignore file if it doesn't already exist.</p>
|
||||
|
||||
<h2 id="OPTIONS">OPTIONS</h2>
|
||||
|
||||
<p> <context></p>
|
||||
|
||||
<p> -l, --local</p>
|
||||
|
||||
<p> Sets the context to the .gitignore file in the current working directory. (default)</p>
|
||||
|
||||
<p> -g, --global</p>
|
||||
|
||||
<p> Sets the context to the global gitignore file fol the current user.</p>
|
||||
|
||||
<p> <pattern></p>
|
||||
|
||||
<p> A space delimited list of patterns to append to the file in context.</p>
|
||||
|
||||
<h3 id="PATTERN-FORMAT">PATTERN FORMAT</h3>
|
||||
|
||||
<p>Pattern format as described in the git manual</p>
|
||||
|
||||
<ul>
|
||||
<li><p>A blank line matches no files, so it can serve as a separator for readability. To append a blank line use empty quotes "".</p></li>
|
||||
<li><p>A line starting with # serves as a comment. For example, "# This is a comment"</p></li>
|
||||
<li><p>An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern will become included again. If a negated pattern matches, this will override lower precedence patterns sources. To use an exclamation ! as command line argument it is best placed between single quotes ''. For example, '!src'</p></li>
|
||||
<li><p>If the pattern ends with a slash, it is removed for the purpose of the following description, but it would only find a match with a directory. In other words, foo/ will match a directory foo and paths underneath it, but will not match a regular file or a symbolic link foo (this is consistent with the way how pathspec works in general in git).</p></li>
|
||||
<li><p>If the pattern does not contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the work tree if not from a .gitignore file).</p></li>
|
||||
<li><p>Otherwise, git treats the pattern as a shell glob suitable for consumption by <span class="man-ref">fnmatch<span class="s">(3)</span></span> with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname. For example, "Documentation/*.html" matches "Documentation/git.html" but not "Documentation/ppc/ppc.html" or "tools/perf/Documentation/perf.html".</p></li>
|
||||
<li><p>A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".</p></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h2 id="EXAMPLES">EXAMPLES</h2>
|
||||
|
||||
<p> To lazy to open up <em>.gitignore</em>? me too! simply pass some patterns:</p>
|
||||
|
||||
<pre><code>$ git ignore build "*.o" "*.log"
|
||||
... added 'build'
|
||||
... added '*.o'
|
||||
... added '*.log'
|
||||
</code></pre>
|
||||
|
||||
<p> Running <code>git-ignore</code> without a pattern will display the current patterns:</p>
|
||||
<p> All arguments are optional so calling git-ignore alone will display first the global then the local gitignore files:</p>
|
||||
|
||||
<pre><code>$ git ignore
|
||||
build
|
||||
*.o
|
||||
*.log
|
||||
Global gitignore: /home/alice/.gitignore
|
||||
# Numerous always-ignore extensions
|
||||
*.diff
|
||||
*.err
|
||||
*.orig
|
||||
*.rej
|
||||
*.swo
|
||||
*.swp
|
||||
*.vi
|
||||
*~
|
||||
*.sass-cache
|
||||
|
||||
# OS or Editor folders
|
||||
.DS_Store
|
||||
.Trashes
|
||||
._*
|
||||
Thumbs.db
|
||||
---------------------------------
|
||||
Local gitignore: .gitignore
|
||||
.cache
|
||||
.project
|
||||
.settings
|
||||
.tmproj
|
||||
nbproject
|
||||
</code></pre>
|
||||
|
||||
<p>If you only want to see the global context use the --global argument (for local use --local):</p>
|
||||
|
||||
<pre><code>$ git ignore
|
||||
Global gitignore: /home/alice/.gitignore
|
||||
.DS_Store
|
||||
.Trashes
|
||||
._*
|
||||
Thumbs.db
|
||||
</code></pre>
|
||||
|
||||
<p>To quickly append a new pattern to the default/local context simply:</p>
|
||||
|
||||
<pre><code>$ git ignore *.log
|
||||
Adding pattern(s) to: .gitignore
|
||||
... adding '*.log'
|
||||
</code></pre>
|
||||
|
||||
<p>You can now configure any patterns without ever using an editor, with a context and pattern arguments:
|
||||
The resulting configuration is also returned for your convenience.</p>
|
||||
|
||||
<pre><code>$ git ignore --local "" "# Temporary files" *.tmp "*.log" tmp/* "" "# Files I'd like to keep" '!work' ""
|
||||
Adding pattern(s) to: .gitignore
|
||||
... adding ''
|
||||
... adding '# Temporary files'
|
||||
... adding 'index.tmp'
|
||||
... adding '*.log'
|
||||
... adding 'tmp/*'
|
||||
... adding ''
|
||||
... adding '# Files I'd like to keep'
|
||||
... adding '!work'
|
||||
... adding ''
|
||||
|
||||
Local gitignore: .gitignore
|
||||
|
||||
# Temporary files
|
||||
index.tmp
|
||||
*.log
|
||||
|
||||
# Files I'd like to keep
|
||||
!work
|
||||
</code></pre>
|
||||
|
||||
<h2 id="AUTHOR">AUTHOR</h2>
|
||||
|
||||
<p>Written by Tj Holowaychuk <<a href="mailto:tj@vision-media.ca" data-bare-link="true">tj@vision-media.ca</a>></p>
|
||||
<p>Written by Tj Holowaychuk <<a href="mailto:tj@vision-media.ca" data-bare-link="true">tj@vision-media.ca</a>> and Tema Bolshakov <<a href="mailto:tweekane@gmail.com" data-bare-link="true">tweekane@gmail.com</a>>
|
||||
and Nick Lombard <<a href="mailto:github@jigsoft.co.za" data-bare-link="true">github@jigsoft.co.za</a>></p>
|
||||
|
||||
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
|
||||
|
||||
|
|
@ -117,7 +202,7 @@ build
|
|||
|
||||
<ol class='man-decor man-foot man foot'>
|
||||
<li class='tl'></li>
|
||||
<li class='tc'>March 2011</li>
|
||||
<li class='tc'>July 2012</li>
|
||||
<li class='tr'>git-ignore(1)</li>
|
||||
</ol>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,35 +1,122 @@
|
|||
git-ignore(1) -- Add .gitignore patterns
|
||||
=======================================
|
||||
========================================
|
||||
|
||||
## SYNOPSIS
|
||||
|
||||
`git-ignore` [<pattern>...]
|
||||
`git-ignore` [<context>] [<pattern> [<pattern>]...]
|
||||
|
||||
## DESCRIPTION
|
||||
|
||||
Adds the given _pattern_s to a gitignore file.
|
||||
Adds the given _pattern_s to a .gitignore file if it doesn't already exist.
|
||||
|
||||
## OPTIONS
|
||||
|
||||
<context>
|
||||
|
||||
-l, --local
|
||||
|
||||
Sets the context to the .gitignore file in the current working directory. (default)
|
||||
|
||||
-g, --global
|
||||
|
||||
Sets the context to the global gitignore file fol the current user.
|
||||
|
||||
<pattern>
|
||||
|
||||
A space delimited list of patterns to append to the file in context.
|
||||
|
||||
### PATTERN FORMAT
|
||||
|
||||
Pattern format as described in the git manual
|
||||
|
||||
* A blank line matches no files, so it can serve as a separator for readability. To append a blank line use empty quotes "".
|
||||
|
||||
* A line starting with # serves as a comment. For example, "# This is a comment"
|
||||
|
||||
* An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern will become included again. If a negated pattern matches, this will override lower precedence patterns sources. To use an exclamation ! as command line argument it is best placed between single quotes ''. For example, '!src'
|
||||
|
||||
* If the pattern ends with a slash, it is removed for the purpose of the following description, but it would only find a match with a directory. In other words, foo/ will match a directory foo and paths underneath it, but will not match a regular file or a symbolic link foo (this is consistent with the way how pathspec works in general in git).
|
||||
|
||||
* If the pattern does not contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the work tree if not from a .gitignore file).
|
||||
|
||||
* Otherwise, git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname. For example, "Documentation/*.html" matches "Documentation/git.html" but not "Documentation/ppc/ppc.html" or "tools/perf/Documentation/perf.html".
|
||||
|
||||
* A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
|
||||
|
||||
|
||||
## EXAMPLES
|
||||
|
||||
To lazy to open up _.gitignore_? me too! simply pass some patterns:
|
||||
|
||||
$ git ignore build "*.o" "*.log"
|
||||
... added 'build'
|
||||
... added '*.o'
|
||||
... added '*.log'
|
||||
|
||||
Running `git-ignore` without a pattern will display the current patterns:
|
||||
All arguments are optional so calling git-ignore alone will display first the global then the local gitignore files:
|
||||
|
||||
$ git ignore
|
||||
build
|
||||
*.o
|
||||
*.log
|
||||
Global gitignore: /home/alice/.gitignore
|
||||
# Numerous always-ignore extensions
|
||||
*.diff
|
||||
*.err
|
||||
*.orig
|
||||
*.rej
|
||||
*.swo
|
||||
*.swp
|
||||
*.vi
|
||||
*~
|
||||
*.sass-cache
|
||||
|
||||
# OS or Editor folders
|
||||
.DS_Store
|
||||
.Trashes
|
||||
._*
|
||||
Thumbs.db
|
||||
---------------------------------
|
||||
Local gitignore: .gitignore
|
||||
.cache
|
||||
.project
|
||||
.settings
|
||||
.tmproj
|
||||
nbproject
|
||||
|
||||
If you only want to see the global context use the --global argument (for local use --local):
|
||||
|
||||
$ git ignore
|
||||
Global gitignore: /home/alice/.gitignore
|
||||
.DS_Store
|
||||
.Trashes
|
||||
._*
|
||||
Thumbs.db
|
||||
|
||||
To quickly append a new pattern to the default/local context simply:
|
||||
|
||||
$ git ignore *.log
|
||||
Adding pattern(s) to: .gitignore
|
||||
... adding '*.log'
|
||||
|
||||
You can now configure any patterns without ever using an editor, with a context and pattern arguments:
|
||||
The resulting configuration is also returned for your convenience.
|
||||
|
||||
$ git ignore --local "" "# Temporary files" *.tmp "*.log" tmp/* "" "# Files I'd like to keep" '!work' ""
|
||||
Adding pattern(s) to: .gitignore
|
||||
... adding ''
|
||||
... adding '# Temporary files'
|
||||
... adding 'index.tmp'
|
||||
... adding '*.log'
|
||||
... adding 'tmp/*'
|
||||
... adding ''
|
||||
... adding '# Files I'd like to keep'
|
||||
... adding '!work'
|
||||
... adding ''
|
||||
|
||||
Local gitignore: .gitignore
|
||||
|
||||
# Temporary files
|
||||
index.tmp
|
||||
*.log
|
||||
|
||||
# Files I'd like to keep
|
||||
!work
|
||||
|
||||
## AUTHOR
|
||||
|
||||
Written by Tj Holowaychuk <<tj@vision-media.ca>>
|
||||
Written by Tj Holowaychuk <<tj@vision-media.ca>> and Tema Bolshakov <<tweekane@gmail.com>>
|
||||
and Nick Lombard <<github@jigsoft.co.za>>
|
||||
|
||||
## REPORTING BUGS
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue