查看 git 版本
git --version
git 配置
git config --global user.name “your name”
git config --global user.email “your email”
保存密码
git config --global credential.helper store
查看配置
git config --list
创建仓库
-
创建仓库
git init -
克隆远程服务器仓库
git clone [url]
- 工作区 working directory
就是本地的文件目录 - 暂存区 staging area
就是 git add 后的文件 - 本地仓库 local repository
就是 git commit 后的文件 - 远程仓库 remote repository
就是 git push 后的文件
查看分支
git branch
查看提交信息
git log / git log --oneline
查看状态
git status
添加文件
- 添加所有文件
git add . - 添加指定文件
git add [file]
撤掉
git reset
查看文件差异
git diff
删除文件
- 删除文件(linux 的命令,删除工作区文件)
rm [file] - 删除文件(git 的命令,删除工作区和本地仓库的文件)
git rm [file]
.gitignore
- 忽略所有 .a 文件
*.a - 但是不要忽略 lib.a,即使有上面的规则
!lib.a - 仅忽略项目根目录下的 TODO 文件
/TODO - 忽略构建目录中的所有文件
build/ - 忽略所有 .txt 文件,无论它们位于哪个子目录中 */.txt
分支
- 创建分支
git branch [branch-name] - 切换分支
git checkout [branch-name]
git switch [branch-name] - 创建并切换分支
git checkout -b [branch-name] - 合并某分支到当前分支
git merge [branch-name] - 删除分支
git branch -d [branch-name]
拉取远程分支
git pull
推送远程分支
git push