Skip to content
- git init . #当前目录初始化为 git 代码仓库
- git init youdir #创建目录,并初始为 git 代码仓库
- git clone url #克隆远程代码仓库
- git config --list # 显示配置信息
- git config --system user.email "test@gitcmd.com" # git 配置系统级别的配置文件
- git config --global user.name "test" # git 配置用户级别的配置文件
- git config --local user.name "test" # git 配置当前项目的配置文件
- git add . # git 把当前的全部文件添加到暂存区
- git add filename # git 添加特定的文件到暂存区
- git status # 显示当前的状态
- git log # 显示当前分支的历史信息
- git log -S “keyword" # 在历史信息中搜索
- git rm filename # 删除工作区的文件,并将删除操作放入暂存区
- git rm --cached filename # 停止追踪该文件,该文件不会再工作区删除,提交后生效。
- git mv filea fileanew # 修改名字,并放入暂存区
- git commit -m "submit msg" # 提交暂存区的内容到 git 仓库
- git commit filea fileb -m "msg" # 提交指定的文件,可以是1个或者多个
- git commit -v # 提交显示diff信息
- git commit --amend -m "msg" # 替代上次的提交,可以修改上一次的提交信息
- git commit --amend filea fileb # 从新提交,并包括指定文件的变化
- git branch # 列出分支
- git branch -r # 列出远程分支
- git branch -a # 列出本地分支
- git branch "new_branch" # 新建一个分支,但不切换的的新的分支
- git branch -b “new_branch" # 新建并且切换的新的分支
- git checkout "new_branch" # 切换到指定的分支
- git checkout - # 切换到上一个分支
- git merge "branchx" # 合并指定分支到当前的分支
- git branch -d "branchname" # 删除指定分支
- git breach origin --delete "branchname" # 删除远程分支
- git tag # 列出tag
- git tag "tagname" # 新建一个 tag
- git tag -d ”tagname" # 删除一个tag
- git show tag # 查看 tag 信息
- git diff # 显示暂存区和工作区的差异
- git diff --cached file # 显示暂存区和上一个commit 的禅意
- git diff HEAD # 显示工作区和当前最近分支的差异
- git fetch [url] # 下载远程仓库的所有变化
- git remove -v # 显示远程所有的仓库
- git remove add "shortname" "url" # 增加一个远程仓库
- git pull "url" # 取回远程仓库的变化
- git push "url" -all # 本地的变化推送的所有的远程仓库
- git checkout file # 恢复暂存区的文件到工作区
- git chekckout "commit" "file" # 恢复历史提交的文件到工作区
- git reset --hard # 重置暂存区的文件