git常用命令
初始化git
git init
创建一个新的本地存储库
git config --global user.name "名字"
git config --global user.email "邮箱"
git clone ssh://user@domain.com/repo.git
克隆现有存储库
查看本地变化
git status
显示工作目录和暂存区的状态
git add <file>
将修改后的file从工作区添加到暂存区
git add .
将所有修改后的代码从工作区添加到暂存区
git commit -m "描述"
将暂存区的代码进行提交
git commit --amend
更改最后一次提交的描述
git log
查看已提交的全部历史
git log --pretty=online
查看已提交的历史记录简化
git stash
将修改的代码存入暂存区
git stash save 'message...'
将修改的代码存入暂存区,并添加注释
git stash list
显示保存进度的列表
git stash pop
恢复最新的进度到工作区;git默认会把工作区和暂存区的改动都恢复到工作区
git stash pop
恢复最新的进度到工作区和暂存区。(尝试将原来暂存区的改动还恢复到暂存区)
git stash pop stash@{1}
恢复指定的进度到工作区;stash_id是通过git stash list命令得到的
分支
git branch
查看当前所在分支
git branch -a
查看所有分支
git checkout <branch>
切换到branch分支
git branch <newbranch>
新建分支
git checkout -b <newbranch>
新建分支,并切换到分支
git checkout -d <branch>
删除本地分支
git checkout --track <remote/branch>
基于远程分支创建一个新的跟踪分支
git tag <tag-name>
用标签标记当前提交
git stash clear
删除所有存储的进度
git stash drop [stash_id]
删除一个存储的进度。如果不指定stash_id,则默认删除最新的存储进度
撤销
1、撤销git add
首先通过git status 查看上次提交的文件
git reset HEAD
如果后面什么都不跟的话 就是上一次add 里面的全部撤销了
git reset HEAD XXX/XXX/XXX.x
就是对某个文件进行撤销了
2、撤销git commit
git reset --soft HEAD^
回退到上一次commit前
更新/发布
git remote -v
查看现有远程仓库的地址url
git remote show <remote>
查看现有远程仓库的地址url信息
git remote add <shortname> <url>
添加名为的新远程存储库
git fetch <remote>从<remote>
下载所有更改,但不要集成到HEAD中
git pull <remote> <branch>
下载更改并直接合并/集成到HEAD中
git push <remote> <branch>
在远程上发布本地更改
git branch -dr <remote/branch>
删除远程仓库上的分支
git push --tags
发布标签