git configuration
git config --local # (currentGitDir)/.git/config
git config --global # ~/.gitconfig
git config --system # /etc/gitconfig
复制代码
优先级
从上到下,逐渐递减
file status lifecycle
At this point, you should have a bona fide Git repository on your local machine, and a checkout or working copy of all of its files in front of you. Typically, you’ll want to start making changes and committing snapshots of those changes into your repository each time the project reaches a state you want to record.
Remember that each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. In short, tracked files are files that Git knows about.
Untracked files are everything else — any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because Git just checked them out and you haven’t edited anything.
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. As you work, you selectively stage these modified files and then commit all those staged changes, and the cycle repeats.
我们可以看到只有两中文件形式,一种是追踪文件形式一种是未追踪文件形式.
复制代码
git commit
#or use git commit -am "commit message"
#but need add previous
git add .
git commit -m "commit message"
复制代码
git cat-file
git cat-file -p hash
#git cat-file -p HEAD
#tree 732576b05340242b4231f13b5d2d1f2b79b48b4f
#parent ae8b33a221058055149b3357825493f8a1fc3fb3
#author huskyui <2207019991@qq.com> 1556800087 -0700
#committer huskyui <2207019991@qq.com> 1556800087 -0700
#
#third commit
复制代码
探究git的文件存储
首先我们使用git hash-object --stdin把我要保存的数据打印出对应哈希加密(sha1)的
hash值
然后将这个数据输入进c.txt这个文件,并将他提交
执行git cat-file -p HEAD可以查找到树,
我们这次使用git cat-file -p 这个树的hash,可以查看文本,
我们清楚看到第三个c.txt的hash和我们刚开始打印出来的东西一样
下面查看他存储在哪吧
在每个仓库的有个隐式文件.git
我们查看 ./git/object
里面有很多文件,我们打开,hash值的前两个字母的文件夹,里面的文件对应hash两位后的字符串
在这里,我做了个有趣的试验,将文件提交后,又修改了一下,
我们可以找到.git/object里面新的文件,
旧的文件可以找到,新的文件也可以找到,也许这样可以实现回退吧.
复制代码
huskyui@ubuntu:~$ echo "aaa"|git hash-object --stdin
72943a16fb2c8f38f9dde202b7a70ccc19c52f34
huskyui@ubuntu:~/Desktop/git/lesson03$ cat c.txt
aaa
huskyui@ubuntu:~/Desktop/git/lesson03$ git cat-file -p HEAD
tree 27bec35d12fd2435823df93eb1f39622f46051d2
parent 1ac6576b5e450f5e23238fbf87bc1d9cdf916366
author huskyui <2207019991@qq.com> 1556801948 -0700
committer huskyui <2207019991@qq.com> 1556801948 -0700
fourth commit
huskyui@ubuntu:~/Desktop/git/lesson03$ git cat-file -p 27bec35d12fd2435823df93eb1f39622f46051d2
100644 blob 340fef996d5ad07e8c2b9e3f413798abec2bc43d a.txt
100644 blob f6ab3cf9d6e218cdcc1ca089327389503b152bf8 b.txt
100644 blob 72943a16fb2c8f38f9dde202b7a70ccc19c52f34 c.txt
c.txt hash
huskyui@ubuntu:~/Desktop/git/lesson03$ cd .git
huskyui@ubuntu:~/Desktop/git/lesson03/.git$ cd objects/
huskyui@ubuntu:~/Desktop/git/lesson03/.git/objects$ cd 72
huskyui@ubuntu:~/Desktop/git/lesson03/.git/objects/72$ ls
943a16fb2c8f38f9dde202b7a70ccc19c52f34
复制代码