005_git专题

一、仓库管理

➜ gittest git:(master) git config --local user.name "arunguang"
➜ gittest git:(master) git config --local user.email "arunguang@gmail.com"

➜ gittest git:(master) git config --local --list
user.name=arunguang
user.email=arunguang@gmail.com

--global < --local(local优先级最高)

  

解释及实操:

(1)
git add readme.md    #把该文件放入git暂存区,通过git管理起来.
git add -u                  #all tracked files in the entire working tree are updated,即把所有已经加到暂存区的文件的更新一块添加更新

git reset --hard  #清理掉自commit以后暂存区的所有改变(非常危险)
--hard   Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.
(2)变更文件名
git mv readme.md README.md  
(3)git log详解
git log                        #git log后面不加任何分支,默认是查看当前分支的修改历史
git log --all                 #查看所有分支的修改历史
git log --oneline          #以简短的方式查看git提交的历史记录
git log -n 2                 #限制显示查看git log提交历史记录的最近几条
(3)分支管理
git checkout -b temp c6d9fd798e3cb652bd2977663b9e7fcc391b711a   #基于git log的某个点创建分支
git commit -am"second"  #-a, --all  Tell the command to automatically stage files that have been modified and deleted
git log --all --graph --oneline       #以图形化的方式查看更改历史
* fe6b335 (HEAD -> temp) second
| * 3538299 (master) mv readme to README.md
|/
* c6d9fd7  On branch master  Changes to be committed:   modified:   readme.md
* 621445a xxx1
(4)查看帮助
git help -web log                         #以网页方式查看帮助
(5)gitk #图形管理工具

二、.git目录解密

(1)
➜  .git git:(temp) cat HEAD
ref: refs/heads/temp                               #指向当前的所在分支
cat .git/config
[core]
	repositoryformatversion = 0
....
[user]
	name = arun6688                           #更改git的user.name的配置
	email = arunguang@gmail.com
➜  gittest git:(master) git config --local user.name      #再次查看已经更改了
arun6688
➜  gittest git:(master) git config --local user.name 'arunold'      #再次查看config文件也已经更改了
(2).git/refs/ 目录
➜  heads git:(master) cat master
3538299062b25ce5e36e9467d0c204837f273fcb
➜  heads git:(master) cat temp
fe6b335bcca87443dd907668bd2ce388f14eddc2
➜  heads git:(master) git cat-file -t 3538299062b25ce5e36e9467d0c204837f273fcb  #-t查看对象命令
commit
➜  heads git:(master) git cat-file -t fe6b335bcca87443dd907668bd2ce388f14eddc2
commit
➜  heads git:(master) git branch -av
* master 3538299 mv readme to README.md
  temp   fe6b335 second
➜  tags git:(master) git cat-file -p 293406d5c363001f169321e3008053c445e1b521  #-p查看对象内容
object 3538299062b25ce5e36e9467d0c204837f273fcb
type commit
tag test1.0
tagger arunold <arunguang@gmail.com> 1544517262 +0800

this is tag test
(2)
➜  35 git:(master) pwd
.git/objects/35
➜  35 git:(master) ls
38299062b25ce5e36e9467d0c204837f273fcb
➜  35 git:(master) git cat-file -t 3538299062b25ce5e36e9467d0c204837f273fcb  #目录+文件名即是git对象的hash值
commit
➜  35 git:(master) git cat-file -p 3538299062b25ce5e36e9467d0c204837f273fcb
tree 9a522cb3bad21d631a84b9264ffb315602fbb079
parent c6d9fd798e3cb652bd2977663b9e7fcc391b711a
author arunguang <arunguang@gmail.com> 1544512480 +0800
committer arunguang <arunguang@gmail.com> 1544512480 +0800

mv readme to README.md

三、commit tree  blob是git中主要的对象

tree对应的是文件夹.

四、常见的企业中使用的git写作方式

https://en.wikipedia.org/wiki/Rolling_release

https://www.git-tower.com/learn/git/ebook/cn/command-line/advanced-topics/git-flow

常用:https://guides.github.com/introduction/flow/

------------------------------------------------------------------------

一、文件管理

(1)git恢复删除文件

➜  git:(master) ✗ git ls-files --deleted
camel-agent-deploy-update.sh
➜  git:(master) ✗ git checkout -- camel-agent-deploy-update.sh
➜  git:(master) ls    #看到已经恢复了
camel-agent-deploy-update.sh

(2)

git log             #查看git整个的提交目录日志
git log -p files #查看某个文件的详细修改记录

参考:http://blog.csdn.net/whu_zhangmin/article/details/18596665

三、分支管理

git branch -a看下ansible分支的名称
git checkout -b ansible分支  eg:git checkout -b ansible2 origin/ansible
pip install -e `pwd` #-e, --editable <path/url>   Install a project in editable mode (i.e. setuptools "develop mode") from a local project path or a VCS url.

四、开发nginx代码的良好使用方式

为了不污染nginx本身的代码,所以一般开发人员会用git diff生成差异的patch文件,然后到真正编译上线的时候再根据diff出的patch文件apply到现有的代码上,这样新添加的代码就会添加到原有nginx代码上,再进行编译即可

git diff > add-ssl-status.patch       #生成patch文件
git apply add-ssl-status.patch        #把patch文件的git差异变更代码加入到现有的nginx中
原文地址:https://www.cnblogs.com/itcomputer/p/7148577.html