博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
git 笔记
阅读量:6074 次
发布时间:2019-06-20

本文共 9434 字,大约阅读时间需要 31 分钟。

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 statusfatal: 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 
..." 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 statusexecve("/usr/bin/git", ["git", "status"], [/* 29 vars */]) = 0access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)open("/etc/ld.so.cache", O_RDONLY)      = 3open("/lib64/libz.so.1", O_RDONLY)      = 3open("/lib64/libpthread.so.0", O_RDONLY) = 3open("/lib64/libc.so.6", O_RDONLY)      = 3getcwd("/home/git/repo/text_repo", 4096) = 25stat(".git", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0access(".git/objects", X_OK)            = 0access(".git/refs", X_OK)               = 0lstat(".git/HEAD", {st_mode=S_IFREG|0664, st_size=23, ...}) = 0open(".git/HEAD", O_RDONLY)             = 3access("/etc/gitconfig", R_OK)          = -1 ENOENT (No such file or directory)access("/root/.gitconfig", R_OK)        = 0open("/root/.gitconfig", O_RDONLY)      = 3stat(".git", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0access(".git/config", R_OK)             = 0open(".git/config", O_RDONLY)           = 3access("/etc/gitconfig", R_OK)          = -1 ENOENT (No such file or directory)access("/root/.gitconfig", R_OK)        = 0open("/root/.gitconfig", O_RDONLY)      = 3access(".git/config", R_OK)             = 0open(".git/config", O_RDONLY)           = 3stat(".git", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0getcwd("/home/git/repo/text_repo", 1024) = 25chdir(".git")                           = 0getcwd("/home/git/repo/text_repo/.git", 4096) = 30lstat("/home/git/repo/text_repo/.git", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0chdir("/home/git/repo/text_repo")       = 0chdir("/home/git/repo/text_repo")       = 0lstat(".git/HEAD", {st_mode=S_IFREG|0664, st_size=23, ...}) = 0open(".git/HEAD", O_RDONLY)             = 3lstat(".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)        = 0open("/root/.gitconfig", O_RDONLY)      = 3access(".git/config", R_OK)             = 0open(".git/config", O_RDONLY)           = 3lstat(".git/MERGE_HEAD", 0x7fffbc771c80) = -1 ENOENT (No such file or directory)open(".git/index", O_RDONLY)            = 3lstat("HEAD", {st_mode=S_IFREG|0664, st_size=23, ...}) = 0lstat("config", {st_mode=S_IFREG|0664, st_size=66, ...}) = 0lstat("description", {st_mode=S_IFREG|0664, st_size=73, ...}) = 0lstat("hooks/applypatch-msg.sample", {st_mode=S_IFREG|0775, st_size=452, ...}) = 0lstat("hooks/commit-msg.sample", {st_mode=S_IFREG|0775, st_size=896, ...}) = 0lstat("hooks/post-commit.sample", {st_mode=S_IFREG|0775, st_size=160, ...}) = 0lstat("hooks/post-receive.sample", {st_mode=S_IFREG|0775, st_size=548, ...}) = 0lstat("hooks/post-update.sample", {st_mode=S_IFREG|0775, st_size=189, ...}) = 0lstat("hooks/pre-applypatch.sample", {st_mode=S_IFREG|0775, st_size=398, ...}) = 0lstat("hooks/pre-commit.sample", {st_mode=S_IFREG|0775, st_size=1578, ...}) = 0lstat("hooks/pre-rebase.sample", {st_mode=S_IFREG|0775, st_size=4951, ...}) = 0lstat("hooks/prepare-commit-msg.sample", {st_mode=S_IFREG|0775, st_size=1239, ...}) = 0lstat("hooks/update.sample", {st_mode=S_IFREG|0775, st_size=3611, ...}) = 0lstat("info/exclude", {st_mode=S_IFREG|0664, st_size=240, ...}) = 0lstat("readme.txt", {st_mode=S_IFREG|0664, st_size=12, ...}) = 0lstat(".git/HEAD", {st_mode=S_IFREG|0664, st_size=23, ...}) = 0open(".git/HEAD", O_RDONLY)             = 3lstat(".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)       = 0open(".git/info/exclude", O_RDONLY)     = 3open(".", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3open(".gitignore", O_RDONLY)            = -1 ENOENT (No such file or directory)open("hooks/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4open("hooks/.gitignore", O_RDONLY)      = -1 ENOENT (No such file or directory)open("branches/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4open("info/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4open("info/.gitignore", O_RDONLY)       = -1 ENOENT (No such file or directory)open("refs/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4open("refs/.gitignore", O_RDONLY)       = -1 ENOENT (No such file or directory)open("refs/tags/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 5open("refs/heads/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 5open("objects/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4open("objects/.gitignore", O_RDONLY)    = -1 ENOENT (No such file or directory)open("objects/pack/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 5open("objects/info/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 5# On branch master## Initial commit## Changes to be committed:#   (use "git rm --cached 
..." 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-prefixa/b/[root@localhost b]# pwd/home/git/demo/a/b[root@localhost b]#

显示从当前目录cd后退up到git根目录的深度:git rev-parse --show-cdup

[root@localhost b]# lsc[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 commitgit 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.barefalse[root@localhost text_repo]# git config core.filemodetrue[root@localhost text_repo]# [root@localhost text_repo]# git config -e[core]        repositoryformatversion = 0        filemode = true        bare = false        logallrefupdates = true

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/osxlinux/p/3298599.html

你可能感兴趣的文章
对 Sea.js 进行配置(一) seajs.config
查看>>
dom4j解析xml文件
查看>>
第六周
查看>>
解释一下 P/NP/NP-Complete/NP-Hard 等问题
查看>>
javafx for android or ios ?
查看>>
微软职位内部推荐-Senior Software Engineer II-Sharepoint
查看>>
sql 字符串操作
查看>>
【转】Android布局优化之ViewStub
查看>>
网络安全管理技术作业-SNMP实验报告
查看>>
根据Uri获取文件的绝对路径
查看>>
Flutter 插件开发:以微信SDK为例
查看>>
.NET[C#]中NullReferenceException(未将对象引用到实例)是什么问题?如何修复处理?...
查看>>
边缘控制平面Ambassador全解读
查看>>
Windows Phone 7 利用计时器DispatcherTimer创建时钟
查看>>
程序员最喜爱的12个Android应用开发框架二(转)
查看>>
vim学习与理解
查看>>
DIRECTSHOW在VS2005中PVOID64问题和配置问题
查看>>
MapReduce的模式,算法以及用例
查看>>
《Advanced Linux Programming》读书笔记(1)
查看>>
zabbix agent item
查看>>