一 摘要
本文主要介绍git常用命令及配置。
二 环境信息
2.1 git版本
C:\Users>git --version
git version 2.24.0.windows.2
三 常见场景
3.1 某类文件不想push 到git 远程库
参考官方文档 https://git-scm.com/docs/gitignore
比如c&c++ 编译的exe 文件
3.1.1 修改配置
修改项目目录下 .git/info/exclude 文件
新增*.exe 即可
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
*.exe
3.1.1 验证
PS D:\jichu\data-structure-yanweimin> git add .
PS D:\jichu\data-structure-yanweimin> git status
On branch develop
Your branch is up to date with 'origin/develop'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: cpp/chapter0/0-1.cpp
new file: cpp/chapter0/0-2.cpp
new file: cpp/chapter0/0-3.cpp
new file: cpp/chapter1/1.4/1.4.cpp
new file: cpp/chapter2/2.13-.214/2.13-2.14.cpp
new file: cpp/chapter2/2.13-.214/book.txt
new file: cpp/chapter2/2.15linkedlist/2.15linkedlist.cpp
new file: cpp/chapter2/2.15linkedlist/listA.txt
new file: cpp/chapter2/2.15linkedlist/listB.txt
new file: cpp/chapter2/2.15sequencelist/2.15sequencelist.cpp
new file: cpp/chapter2/2.15sequencelist/listA.txt
new file: cpp/chapter2/2.15sequencelist/listB.txt
new file: cpp/chapter2/2.16/2.16.cpp
new file: cpp/chapter2/2.16/ListA.txt
new file: cpp/chapter2/2.16/ListB.txt
new file: cpp/chapter2/2.17/2.17.cpp
new file: cpp/chapter2/2.17/ListA.txt
new file: cpp/chapter2/2.17/ListB.txt
new file: cpp/chapter2/2.18-2.19/2.18-2.19.cpp
new file: cpp/chapter2/2.18-2.19/PolyA.txt
new file: cpp/chapter2/2.18-2.19/PolyB.txt
new file: cpp/chapter2/2.6-2.12/2.6-2.12.cpp
new file: cpp/chapter2/2.6-2.12/book.txt
new file: cpp/chapter3/3.1-3.4/3.1-3.4.cpp
new file: cpp/chapter3/3.1-3.4/SqStack.txt
new file: cpp/chapter3/3.10/3.10.cpp
new file: cpp/chapter3/3.10/3.10.h
new file: cpp/chapter3/3.11-3.15/3.11-3.15.cpp
new file: cpp/chapter3/3.11-3.15/QNode.txt
new file: cpp/chapter3/3.5-3.8/3.5-3.8.cpp
new file: cpp/chapter3/3.5-3.8/SqStack.txt
new file: cpp/chapter3/3.9/3.9.cpp
可见 exe 文件并未add.
push 到远程仓库 也不包含.exe 文件
四 常用命令
4.1 gitclone 所有分支
gitclone 默认只会克隆主分支,需要执行以下命令将所有分支克隆
for i in `git branch -a | grep remote | grep -v HEAD | grep -v master`; do git branch --track ${i#remotes/origin/} $i; done