centos 安装git:
yum install git git-core
repository 仓库,设置全局用户名以及邮箱。
git config --global user.name "yourname" git config --global user.email "xxx@xxx.com"
git init #初始化本地仓库。如果当前目录没有.git目录则创建。.git就是当前目录的版本仓库。 git add . #添加当前目录到版本地.git库 git commit -m “要提交的说明” 提交当前目录的文件到版本库
如果不是在某一个仓库的话,git status 查不到.git版本仓库,是没有作用的。
[root@localhost home]# git status
fatal: Not a git repository (or any of the parent directories): .git #便是在当前目录下没有找到叫.git repository(仓库)
进入到某一个你创建的仓库:
[root@localhost text_repo]# git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: HEAD # new file: config # new file: description # new file: hooks/applypatch-msg.sample # new file: hooks/commit-msg.sample # new file: hooks/post-commit.sample # new file: hooks/post-receive.sample # new file: hooks/post-update.sample # new file: hooks/pre-applypatch.sample # new file: hooks/pre-commit.sample # new file: hooks/pre-rebase.sample # new file: hooks/prepare-commit-msg.sample # new file: hooks/update.sample # new file: info/exclude # new file: readme.txt # [root@localhost text_repo]# pwd /home/git/repo/text_repo [root@localhost text_repo]#
git 访问本地磁盘的仓库是依次递归访问
[root@localhost text_repo]# strace -e 'trace=file' git status execve("/usr/bin/git", ["git", "status"], [/* 29 vars */]) = 0 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY) = 3 open("/lib64/libz.so.1", O_RDONLY) = 3 open("/lib64/libpthread.so.0", O_RDONLY) = 3 open("/lib64/libc.so.6", O_RDONLY) = 3 getcwd("/home/git/repo/text_repo", 4096) = 25 stat(".git", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 access(".git/objects", X_OK) = 0 access(".git/refs", X_OK) = 0 lstat(".git/HEAD", {st_mode=S_IFREG|0664, st_size=23, ...}) = 0 open(".git/HEAD", O_RDONLY) = 3 access("/etc/gitconfig", R_OK) = -1 ENOENT (No such file or directory) access("/root/.gitconfig", R_OK) = 0 open("/root/.gitconfig", O_RDONLY) = 3 stat(".git", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 access(".git/config", R_OK) = 0 open(".git/config", O_RDONLY) = 3 access("/etc/gitconfig", R_OK) = -1 ENOENT (No such file or directory) access("/root/.gitconfig", R_OK) = 0 open("/root/.gitconfig", O_RDONLY) = 3 access(".git/config", R_OK) = 0 open(".git/config", O_RDONLY) = 3 stat(".git", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 getcwd("/home/git/repo/text_repo", 1024) = 25 chdir(".git") = 0 getcwd("/home/git/repo/text_repo/.git", 4096) = 30 lstat("/home/git/repo/text_repo/.git", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 chdir("/home/git/repo/text_repo") = 0 chdir("/home/git/repo/text_repo") = 0 lstat(".git/HEAD", {st_mode=S_IFREG|0664, st_size=23, ...}) = 0 open(".git/HEAD", O_RDONLY) = 3 lstat(".git/refs/heads/master", 0x7fffbc770b10) = -1 ENOENT (No such file or directory) open(".git/packed-refs", O_RDONLY) = -1 ENOENT (No such file or directory) access("/etc/gitconfig", R_OK) = -1 ENOENT (No such file or directory) access("/root/.gitconfig", R_OK) = 0 open("/root/.gitconfig", O_RDONLY) = 3 access(".git/config", R_OK) = 0 open(".git/config", O_RDONLY) = 3 lstat(".git/MERGE_HEAD", 0x7fffbc771c80) = -1 ENOENT (No such file or directory) open(".git/index", O_RDONLY) = 3 lstat("HEAD", {st_mode=S_IFREG|0664, st_size=23, ...}) = 0 lstat("config", {st_mode=S_IFREG|0664, st_size=66, ...}) = 0 lstat("description", {st_mode=S_IFREG|0664, st_size=73, ...}) = 0 lstat("hooks/applypatch-msg.sample", {st_mode=S_IFREG|0775, st_size=452, ...}) = 0 lstat("hooks/commit-msg.sample", {st_mode=S_IFREG|0775, st_size=896, ...}) = 0 lstat("hooks/post-commit.sample", {st_mode=S_IFREG|0775, st_size=160, ...}) = 0 lstat("hooks/post-receive.sample", {st_mode=S_IFREG|0775, st_size=548, ...}) = 0 lstat("hooks/post-update.sample", {st_mode=S_IFREG|0775, st_size=189, ...}) = 0 lstat("hooks/pre-applypatch.sample", {st_mode=S_IFREG|0775, st_size=398, ...}) = 0 lstat("hooks/pre-commit.sample", {st_mode=S_IFREG|0775, st_size=1578, ...}) = 0 lstat("hooks/pre-rebase.sample", {st_mode=S_IFREG|0775, st_size=4951, ...}) = 0 lstat("hooks/prepare-commit-msg.sample", {st_mode=S_IFREG|0775, st_size=1239, ...}) = 0 lstat("hooks/update.sample", {st_mode=S_IFREG|0775, st_size=3611, ...}) = 0 lstat("info/exclude", {st_mode=S_IFREG|0664, st_size=240, ...}) = 0 lstat("readme.txt", {st_mode=S_IFREG|0664, st_size=12, ...}) = 0 lstat(".git/HEAD", {st_mode=S_IFREG|0664, st_size=23, ...}) = 0 open(".git/HEAD", O_RDONLY) = 3 lstat(".git/refs/heads/master", 0x7fffbc76f850) = -1 ENOENT (No such file or directory) lstat(".git/refs/HEAD", 0x7fffbc76f850) = -1 ENOENT (No such file or directory) lstat(".git/refs/tags/HEAD", 0x7fffbc76f850) = -1 ENOENT (No such file or directory) lstat(".git/refs/heads/HEAD", 0x7fffbc76f850) = -1 ENOENT (No such file or directory) lstat(".git/refs/remotes/HEAD", 0x7fffbc76f850) = -1 ENOENT (No such file or directory) lstat(".git/refs/remotes/HEAD/HEAD", 0x7fffbc76f850) = -1 ENOENT (No such file or directory) access(".git/info/exclude", R_OK) = 0 open(".git/info/exclude", O_RDONLY) = 3 open(".", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3 open(".gitignore", O_RDONLY) = -1 ENOENT (No such file or directory) open("hooks/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4 open("hooks/.gitignore", O_RDONLY) = -1 ENOENT (No such file or directory) open("branches/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4 open("info/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4 open("info/.gitignore", O_RDONLY) = -1 ENOENT (No such file or directory) open("refs/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4 open("refs/.gitignore", O_RDONLY) = -1 ENOENT (No such file or directory) open("refs/tags/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 5 open("refs/heads/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 5 open("objects/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4 open("objects/.gitignore", O_RDONLY) = -1 ENOENT (No such file or directory) open("objects/pack/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 5 open("objects/info/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 5 # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: HEAD # new file: config # new file: description # new file: hooks/applypatch-msg.sample # new file: hooks/commit-msg.sample # new file: hooks/post-commit.sample # new file: hooks/post-receive.sample # new file: hooks/post-update.sample # new file: hooks/pre-applypatch.sample # new file: hooks/pre-commit.sample # new file: hooks/pre-rebase.sample # new file: hooks/prepare-commit-msg.sample # new file: hooks/update.sample # new file: info/exclude # new file: readme.txt # [root@localhost text_repo]#
查找git版本仓库的路径:git rev-parse --git-dir
[root@localhost b]# git rev-parse --git-dir /home/git/demo/.git [root@localhost b]# pwd /home/git/demo/a/b [root@localhost b]#
查找git版本的工作目录:git rev-parse --show-toplevel
[root@localhost b]# git rev-parse --show-toplevel /home/git/demo [root@localhost b]# pwd /home/git/demo/a/b [root@localhost b]#
查找工作目录相对的工作目录:git rev-parse --show-prefix
[root@localhost b]# git rev-parse --show-prefix a/b/ [root@localhost b]# pwd /home/git/demo/a/b [root@localhost b]#
显示从当前目录cd后退up到git根目录的深度:git rev-parse --show-cdup
[root@localhost b]# ls c [root@localhost b]# git rev-parse --show-cdup ../../ [root@localhost b]# pwd /home/git/demo/a/b [root@localhost b]#
-------------------------------------------------------------------------------------------------------------------------------------------------
git config 对.git仓库版本进行编辑。
三个配置文件。
.git 下的config 是版本库的配置文件。
/home/.gitconfig 或者/root/.gitconfig在家目录下,是全局配置文件。
/etc/gitconfig 系统配置配置文件。
以上三者优先级顺序: .git 下config ----------> 全局配置文件 .gitconfig ---------------->系统配置文件/etc/gitconfig
-------------------------------------------------------------------------------------------------------------------------------------------------
git config -e 是对根目录.git下的config进行编辑。
[git@localhost text_repo]$ git config -e [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true
git 对全局配置文件进行编辑git config -e --global。
[root@localhost ~]# git config -e --global [user] name = osxlinux email = osx1260@163.com [color] ui = true
对系统配置文件进行编辑。
[root@localhost ~]# git config --system alias.st status [root@localhost ~]# git config --system alias.br branch [root@localhost ~]# git config --system alias.co checkout [root@localhost ~]# git config --system alias.ci commit git config -e --system [root@localhost ~]# git config -e --system [alias] ci = commit co = checkout br = branch st = status
查看某一个参数的配置:
[root@localhost text_repo]# git config core.bare false [root@localhost text_repo]# git config core.filemode true [root@localhost text_repo]# [root@localhost text_repo]# git config -e [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true