Git 初始化分析

$ git init hello

Initialized emptyGit repository in /home/yang shuang/hello/.git/

 

生成的文件目录结构:

yangshuang@arthur_yang ~/hello

$ ls -a

./  ../ .git/

 

 

Git 查询版本库的流程:

 

orge@pc:~/study/git-study/hello-demo$strace -e 'trace=file' git status

execve("/usr/bin/git",["git", "status"], [/* 44 vars */]) = 0

access("/etc/ld.so.nohwcap",F_OK)      = -1 ENOENT (No such file ordirectory)

access("/etc/ld.so.preload",R_OK)      = -1 ENOENT (No such file ordirectory)

open("/etc/ld.so.cache",O_RDONLY|O_CLOEXEC) = 3

access("/etc/ld.so.nohwcap",F_OK)      = -1 ENOENT (No such file ordirectory)

open("/lib/x86_64-linux-gnu/libz.so.1",O_RDONLY|O_CLOEXEC) = 3

access("/etc/ld.so.nohwcap",F_OK)      = -1 ENOENT (No such file ordirectory)

open("/lib/x86_64-linux-gnu/libresolv.so.2",O_RDONLY|O_CLOEXEC) = 3

access("/etc/ld.so.nohwcap",F_OK)      = -1 ENOENT (No such file ordirectory)

open("/lib/x86_64-linux-gnu/libpthread.so.0",O_RDONLY|O_CLOEXEC) = 3

access("/etc/ld.so.nohwcap",F_OK)      = -1 ENOENT (No such file ordirectory)

open("/lib/x86_64-linux-gnu/libc.so.6",O_RDONLY|O_CLOEXEC) = 3

open("/usr/lib/locale/locale-archive",O_RDONLY|O_CLOEXEC) = 3

getcwd("/home/orge/study/git-study/hello-demo",4096) = 38

stat(".",{st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0

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 ordirectory)

access("/home/orge/.gitconfig",R_OK)   = 0

open("/home/orge/.gitconfig",O_RDONLY) = 3

access(".git/config",R_OK)             = 0

open(".git/config",O_RDONLY)           = 3

stat(".",{st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0

getcwd("/home/orge/study/git-study/hello-demo",1024) = 38

chdir(".")                              = 0

getcwd("/home/orge/study/git-study/hello-demo",4096) = 38

lstat("/home/orge/study/git-study/hello-demo",{st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0

chdir("/home/orge/study/git-study/hello-demo")= 0

stat(".git",{st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0

access("/etc/gitconfig",R_OK)          = -1 ENOENT (No such fileor directory)

access("/home/orge/.gitconfig",R_OK)   = 0

open("/home/orge/.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/orge/study/git-study/hello-demo",1024) = 38

chdir(".git")                           = 0

getcwd("/home/orge/study/git-study/hello-demo/.git",4096) = 43

lstat("/home/orge/study/git-study/hello-demo/.git",{st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0

chdir("/home/orge/study/git-study/hello-demo")= 0

chdir("/home/orge/study/git-study/hello-demo")= 0

lstat(".git/HEAD",{st_mode=S_IFREG|0664, st_size=23, ...}) = 0

open(".git/HEAD",O_RDONLY)             = 3

lstat(".git/refs/heads/master",0x7ffff63b3210) = -1 ENOENT (No such file or directory)

open(".git/packed-refs",O_RDONLY)      = -1 ENOENT (No such fileor directory)

open(".git/index",O_RDONLY)            = -1 ENOENT (No suchfile or directory)

open("/home/orge/study/git-study/hello-demo/.gitmodules",O_RDONLY) = -1 ENOENT (No such file or directory)

access("/etc/gitconfig",R_OK)          = -1 ENOENT (No such fileor directory)

access("/home/orge/.gitconfig",R_OK)   = 0

open("/home/orge/.gitconfig",O_RDONLY) = 3

access(".git/config",R_OK)             = 0

open(".git/config",O_RDONLY)           = 3

lstat(".git/MERGE_HEAD",0x7ffff63b4380) = -1 ENOENT (No such file or directory)

lstat(".git/CHERRY_PICK_HEAD",0x7ffff63b4380) = -1 ENOENT (No such file or directory)

open(".git/index",O_RDONLY)            = -1 ENOENT (No suchfile or directory)

readlink(".git/index",0x7ffff63b33b0, 4096) = -1 ENOENT (No such file or directory)

open(".git/index.lock",O_RDWR|O_CREAT|O_EXCL, 0666) = 3

unlink(".git/index.lock")               = 0

lstat(".git/HEAD",{st_mode=S_IFREG|0664, st_size=23, ...}) = 0

open(".git/HEAD",O_RDONLY)             = 3

lstat(".git/refs/heads/master",0x7ffff63b0f40) = -1 ENOENT (No such file or directory)

lstat(".git/refs/HEAD", 0x7ffff63b0f40) =-1 ENOENT (No such file or directory)

lstat(".git/refs/tags/HEAD",0x7ffff63b0f40) = -1 ENOENT (No such file or directory)

lstat(".git/refs/heads/HEAD",0x7ffff63b0f40) = -1 ENOENT (No such file or directory)

lstat(".git/refs/remotes/HEAD",0x7ffff63b0f40) = -1 ENOENT (No such file or directory)

lstat(".git/refs/remotes/HEAD/HEAD",0x7ffff63b0f40) = -1 ENOENT (No such file or directory)

access(".git/info/exclude",R_OK)       = 0

open(".git/info/exclude",O_RDONLY)     = 3

openat(AT_FDCWD,".", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3

open("/usr/share/locale/locale.alias",O_RDONLY|O_CLOEXEC) = 3

open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/git.mo",O_RDONLY) = -1 ENOENT (No such file or directory)

open("/usr/share/locale/en_US.utf8/LC_MESSAGES/git.mo",O_RDONLY) = -1 ENOENT (No such file or directory)

open("/usr/share/locale/en_US/LC_MESSAGES/git.mo",O_RDONLY) = -1 ENOENT (No such file or directory)

open("/usr/share/locale/en.UTF-8/LC_MESSAGES/git.mo",O_RDONLY) = -1 ENOENT (No such file or directory)

open("/usr/share/locale/en.utf8/LC_MESSAGES/git.mo",O_RDONLY) = -1 ENOENT (No such file or directory)

open("/usr/share/locale/en/LC_MESSAGES/git.mo",O_RDONLY) = -1 ENOENT (No such file or directory)

open("/usr/share/locale-langpack/en_US.UTF-8/LC_MESSAGES/git.mo",O_RDONLY) = -1 ENOENT (No such file or directory)

open("/usr/share/locale-langpack/en_US.utf8/LC_MESSAGES/git.mo",O_RDONLY) = -1 ENOENT (No such file or directory)

open("/usr/share/locale-langpack/en_US/LC_MESSAGES/git.mo",O_RDONLY) = -1 ENOENT (No such file or directory)

open("/usr/share/locale-langpack/en.UTF-8/LC_MESSAGES/git.mo",O_RDONLY) = -1 ENOENT (No such file or directory)

open("/usr/share/locale-langpack/en.utf8/LC_MESSAGES/git.mo",O_RDONLY) = -1 ENOENT (No such file or directory)

open("/usr/share/locale-langpack/en/LC_MESSAGES/git.mo",O_RDONLY) = -1 ENOENT (No such file or directory)

# On branch master

#

# Initial commit

#

nothing to commit(create/copy files and use "git add" to track)

 

 

 

API:

 

函数名: access

头文件:io.h(linux中为<unistd.h>)

功 能: 确定文件的访问权限,检查某个文件的存取方式,比如说是只读方式、只写方式等。如果指定的存取方式有效,则函数返回0,否则函数返回-1。

用 法: int access(const char *filename, int amode);

int _access(constchar *path,int mode) ;

 

函数名:open

头文件:#include <fcntl.h>

用  法:int open(const char *pathname, int oflag,... );

返回值:成功则返回文件描述符,否则返回 -1

 

函数名: stat

功 能: 得到文件的信息,将其保存在buf结构中,buf的地址以参数形式传递给stat。

用 法: int _stat(const char *path,struct _stat *buffer)

参数:

constchar *path: 文件名或者目录名

struct_stat *buffer:结构体对象地址

返回值: 返回-1表示失败。

 

函数名: lstat

功 能: 获取一些文件相关的信息

用 法: int lstat(constchar *path, struct stat *buf);

成功执行时,返回0。失败返回-1,errno被设为以下的某个值

EBADF: 文件描述词无效

EFAULT: 地址空间不可访问

ELOOP: 遍历路径时遇到太多的符号连接

ENAMETOOLONG:文件路径名太长

ENOENT:路径名的部分组件不存在,或路径名是空字串

ENOMEM:内存不足

ENOTDIR:路径名的部分组件不是目录

stat和lstat的区别:当文件是一个符号链接时,lstat返回的是该符号链接本身的信息;而stat返回的是该链接指向的文件的信息

 

 

函数名:getcwd

头文件:#include <unistd.h>

定义:char *getcwd(char *buf, size_t size);

功 能:把当前目录的绝对地址保存到 buf 中,buf 的大小为 size。如果 size太小无法保存该地址,返回 NULL 并设置 errno 为 ERANGE。

 

函数名:readlink

头文件: #include<unistd.h>

定义函数:ssize_treadlink(const char *path, char *buf, size_t bufsiz);

函数说明:readlink()会将参数path的符号链接内容存储到参数buf所指的内存空间。若参数bufsiz小于符号连接的内容长度,过长的内容会被截断,如果 readlink 第一个参数指向一个文件而不是符号链接时,readlink 设 置errno 为 EINVAL 并返回 -1。

返回值 :执行成功则返回字符串的字符数,失败返回-1, 错误代码存于errno

 

函数名:chdir

用法:chdir函数用于改变当前工作目录。

 

 

Gitconfig

--system  修改对应配置文件/etc/gitconfig

--global     修改对应配置文件~/.gitconfig

不加参数修改.git/config

 

库配置文件优先级最高

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值