git常用命令

# 下载一个项目和它的整个代码历史
$ git clone [url]

# 添加指定文件到暂存区
$ git add [file1] [file2] ...

# 添加当前目录的所有文件到暂存区
$ git add .

# 提交暂存区到仓库区
$ git commit -m [message]
# 提交暂存区的指定文件到仓库区
$ git commit [file1] [file2] ... -m [message]


# 列出所有本地分支
$ git branch

 

# 列出所有本地分支和远程分支
$ git branch -a


# 新建一个分支,但依然停留在当前分支
$ git branch [branch-name]


# 新建一个分支,并切换到该分支
$ git checkout -b [branch]

# 切换到指定分支,并更新工作区
$ git checkout [branch-name]


# 切换到上一个分支
$ git checkout -


# 删除分支
$ git branch -d [branch-name]


# 显示有变更的文件
$ git status

# 显示当前分支的版本历史
$ git log


# 显示暂存区和工作区的代码差异
$ git diff


# 显示某次提交的元数据和内容变化
$ git show [commit]


# 从本地master拉取代码更新当前分支:branch 一般为master
$ git rebase [branch]



#更新远程仓储
$ git remote update

# 取回远程仓库的变化,并与本地分支合并
$ git pull [remote] [branch]


# 上传本地指定分支到远程仓库
$ git push [remote] [branch]

# 重置暂存区与工作区,与上一次commit保持一致
$ git reset --hard
 
 
posted @ 2018-10-22 12:01  stanljj  阅读(131)  评论(0编辑  收藏  举报