首页 > 学院 > 开发设计 > 正文

git常用命令

2019-11-06 07:09:14
字体:
来源:转载
供稿:网友

git

git初始化git仓库和添加远程仓库添加全局配置信息常用命令branchaddcheckoutdiffresetstashsubmodule

初始化git仓库和添加远程仓库

在目录下执行命令:git init克隆git仓库:git clone git仓库地址

添加全局配置信息

git config --global user.name "Adam"git config --global user.email "Adam@example.com"git config --list 查看全局配置信息

常用命令

git status 查看本地代码状态git commit -m "notes" 提交并添加注释git remote rename x y 将x仓库重命名为y

branch

git branch 查看本地分支git branch -a 查看本地和远程分支git branch branchName 在本地创建branchName分支git checkout -b branchName 在本地创建branchName分支并切换到该分支git branch -d branchName 删除本地branchName分支git push repositoryName branchName 将branchName分支推送到repositoryName仓库git push repositoryName --delete branchName 删除repositoryName仓库的branchName分支

add

git add files 将files添加到暂存区git add -A . 来一次添加所有改变的文件。git add -A 表示添加所有内容git add . 表示添加新文件和编辑过的文件不包括删除的文件git add -u 表示添加编辑或者删除的文件,不包括新添加的文件。

checkout

git checkout files 撤销本地指定files的修改(该修改还未添加到暂区)git checkout . 撤销本地所有的修改(未添加到暂存区的所有修改)git checkout branchName 切换到branchName分支,如果branchName不存在git checkout -b branchName 在本地创建branchName分支并切换到该分支

diff

git diff file 比较当前文件和暂存区文件差异git diff HASH1 HASH2 比较两次提交之间的差异git diff branch1 branch 在两个分支之间比较git diff --staged 比较暂存区和版本库差异git diff --cached 比较暂存区和版本库差异git diff --stat 仅仅比较统计信息

reset

git reset . 将所有修改从暂存区中撤销至本地修改git reset files 将files的修改从暂存区中撤销至本地修改git reset --hard HASH 本地代码撤销至HASH版本且不保留修改git reset --soft HASH 本地代码撤销至HASH版本并保留修改

stash

关于stash的命令

git stash 暂存git stash list 列所有stashgit stash apply 恢复暂存的内容git stash drop 删除暂存区

submodule

git submodule initgit submodule updategit submodule foreach "git command" 递归给子模块执行git command命令
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表