git 使用技巧
目录
git log美化输出
|
|
效果如下:
git 拉取指定目录或文件
-
目录初始化
1git init -
设置远程仓库地址
1git remote add -f origin <origin_url> -
启用
sparse checkout模式,允许克隆子目录1git config core.sparsecheckout true -
在
.git/info/sparse-checkout 文件中指定要拉取的文件夹或文件:1 2## 例如要拉取远程仓库public目录下的所有文件 echo "public/*" >> .git/info/sparse-checkout如果要拉取多个文件夹或文件,只需要在 .git/info/sparse-checkout 文件中添加多个路径即可
-
开始拉取
-
1git pull origin master
git 设置全局用户名、密码、邮箱
-
设置
1 2 3git config --global user.name “user01” git config --global user.password "password" git config --global user.email "test@123.com" -
删除配置
1 2 3git config --global --unset user.name “user01” git config --global --unset user.password "password" git config --global --unset user.email "test@123.com"
设置git push和pull的默认远程分支
|
|
设置git pull免密码
-
执行命令
1git config --global credential.helper store -
命令执行后会在
家目录生成一个.gitconfig,内容如下:1 2[credential] helper = store -
这时再执行
git pull,输入用户名、密码后,相关信息会保存到.git-credentials文件中,下次再次拉取就不用输入密码啦。.git-credentials文件内容结构如下:1http://<USERNAME>:<PASSWORD>@gitlab.com