文章目录
- 前言
- 常用命令
- 配置信息
- 仓库命令
- 增加/删除文件
- 提交代码
- 分支
- 查看信息
- 远程同步
- 撤销
- other
前言
Git常用的各种命令和解析。
常用命令
配置信息
git config --list
git config -e [--global]
git config [--global] user.name "[name]"
git config [--global] user.email "[email]"
仓库命令
git init
git init [project-name]
git clone [https://xxx.git]
增加/删除文件
git add [file1] [file] ...
git add [dir]
git add .
git add -p
git rm [file1] [file2]
git rm --cached [file]
git mv [file-org] [file-renamed]
提交代码
git commit -m [message]
git commit [file1] [file2] ... -m [message]
git commit -a
git commit -v
git commit --amend -m [message]
git commit --amend [file1] [file2] ...
分支
git branch
git branch -r
git branch -a
git branch [branch-name]
git checkout -b [branch]
git branch [branch] [commit]
git branch --track [branch] [remote-branch]
git checkout [branch-name]
git checkout -
git branch --set-upstream [branch] [remote-branch]
git merge [branch]
git cherry-pick [commit]
git branch -d [branch-name]
git push origin --delete [branch-name]
git branch -dr [remote/branch]
查看信息
git status
远程同步
git fetch [remote]
git remote -v
git remote show [remote]
git remote add [shortname] [url]
git pull [remote] [branch]
git push [remote] [branch]
git push [remote] --force
git push [remote] --all
撤销
git checkout [file]
git checkout [commit] [file]
git checkout .
git reset [file]
git reset --hard
git reset [commit]
git reset --hard [commit]
git reset --keep [commit]
git revert [commit]
暂时将未提交的变化移除,稍后再移入
git stash
git stash pop
other
$ git archive