File tree Expand file tree Collapse file tree 5 files changed +249
-0
lines changed
Expand file tree Collapse file tree 5 files changed +249
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ $ brew install git-extras
7373 - ` git unlock `
7474 - ` git reset-file `
7575 - ` git pr `
76+ - ` git root `
7677
7778## git-extras
7879
@@ -694,3 +695,14 @@ From https://github.com/tj/git-extras
694695 * [new ref] refs/pulls/226/head -> pr/226
695696Switched to branch ' pr/226'
696697```
698+
699+ ## git-root
700+
701+ show the path to root directory of git repo
702+
703+ ```bash
704+ $ pwd
705+ .../very-deep-from-root-directory
706+ $ cd `git root`
707+ $ git add . && git commit
708+ ```
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+
3+ git_root () {
4+ git rev-parse --show-toplevel
5+ }
6+
7+ # get the relative path of current path according to root of repo
8+ git_root_relative () {
9+ git rev-parse --show-prefix
10+ }
11+
12+ if test $# -eq 0; then
13+ git_root
14+ else
15+ case " $1 " in
16+ -r|--relative)
17+ git_root_relative
18+ ;;
19+ * )
20+ git_root
21+ ;;
22+ esac
23+ fi
24+
Original file line number Diff line number Diff line change 1+ .\" generated with Ronn/v0.7.3
2+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3+ .
4+ .TH "GIT\- ROOT" "1" "November 2014" "" ""
5+ .
6+ .SH "NAME"
7+ \fB git \- root \fR \- show path of root
8+ .
9+ .SH "SYNOPSIS"
10+ \fB git root \fR \fI OPTIONS \fR
11+ .
12+ .SH "DESCRIPTION"
13+ print the path for the root directory of git repo
14+ .
15+ .SH "OPTIONS"
16+ \- r, \-\- relative
17+ .
18+ .P
19+ show the relative path from root directory to current directory
20+ .
21+ .SH "EXAMPLES"
22+ .
23+ .nf
24+
25+ $ cd \.\.\. /git\- extras/bin
26+ $ git root \- r
27+ bin/
28+ $ git root
29+ /home/\.\.\. /git\- extras
30+ $ cd `git root`
31+ $ pwd
32+ /home/\.\.\. /git\- extras
33+ # then we can
34+ $ git add \. && git commit
35+ .
36+ .fi
37+ .
38+ .SH "AUTHOR"
39+ Written by spacewander <\fI spacewanderlzx@gmail \. com \fR >
40+ .
41+ .SH "REPORTING BUGS"
42+ <\fI https://github \. com/tj/git \- extras/issues \fR >
43+ .
44+ .SH "SEE ALSO"
45+ <\fI https://github \. com/tj/git \- extras \fR >
Original file line number Diff line number Diff line change 1+ git-root(1) -- show path of root
2+ ========================================
3+
4+ ## SYNOPSIS
5+
6+ ` git root ` [ OPTIONS]
7+
8+ ## DESCRIPTION
9+
10+ print the path for the root directory of git repo
11+
12+ ## OPTIONS
13+
14+ -r, --relative
15+
16+ show the relative path from root directory to current directory
17+
18+ ## EXAMPLES
19+
20+
21+ $ cd .../git-extras/bin
22+ $ git root -r
23+ bin/
24+ $ git root
25+ /home/.../git-extras
26+ $ cd `git root`
27+ $ pwd
28+ /home/.../git-extras
29+ # then we can
30+ $ git add . && git commit
31+
32+ ## AUTHOR
33+
34+ Written by spacewander
< ; < [email protected] > > ; 35+
36+ ## REPORTING BUGS
37+
38+ < ; < https://github.com/tj/git-extras/issues > > ;
39+
40+ ## SEE ALSO
41+
42+ < ; < https://github.com/tj/git-extras > > ;
You can’t perform that action at this time.
0 commit comments