Git常用命令

Git命令

git config

git config –global user.name [name] 设置提交代码的用户名

git config –global user.email [email address] 设置提交代码的电子邮件地址

git init

用法:git init [repository name] 创建一个新的代码库

git clone

git clone [url] 通过指定的URL获取一个代码库

git add

git add [file] 将一个文件添加至暂存区

git add * 将多个文件添加至暂存区

git commit

git commit -m [ Type in the commit message] 在版本历史记录中永久记录文件

git commit -a 将提交git add命令添加的所有文件,并提交git add命令之后更改的所有文件。

git diff

git diff 显示尚未添加到暂存区的文件的变更

git diff –staged 显示添加到暂存区的文件与当前最新版本之间的差异

git diff [first branch] [second branch] 显示两个分支之间的差异

git reset

git reset [file] 从暂存区中撤出指定的文件,但可以保留文件的内容

git reset [commit] 撤销指定提交之后的所有提交,并在本地保留变更

git reset –hard [commit] 丢弃所有的历史记录,并回滚到指定的提交

git status

git status 显示所有需要提交的文件

git rm

git rm [file] 删除工作目录中的文件,并将删除动作添加到stage

git log

git log 显示当前分支的版本历史记录

git log –follow[file] 显示某个文件的版本历史记录,包括文件的重命名

git show

git show [commit] 显示指定提交的元数据以及内容变更

git tag

git tag [commitID] 给指定的提交添加标签

git branch

git branch 显示当前代码库中所有的本地分支

git branch -r 列出所有远程分支

git branch [branch name] 创建一个分支

git branch -d [branch name] 删除指定的分支

git checkout

git checkout [branch name] 切换分支

git checkout -b [branch name] 创建一个分支,并切换到新分支上

git merge

git merge [branch name] 将指定分支的历史记录合并到当前分支

git remote

git remote add [variable name] [Remote Server Link] 将本地的代码库连接到远程服务器

git push

git push [variable name] master 将主分支上提交的变更发送到远程代码库

git push [variable name] [branch] 将指定分支上的提交发送到远程代码库

git push –all [variable name] 将所有分支发送到远程代码库

git push [variable name] :[branch name] 删除远程代码库上的一个分支

git pull

git pull [Repository Link] 获取远程服务器上的变更,并合并到你的工作目录

git stash

git stash save 临时保存所有修改的文件

git stash pop 恢复最近一次stash(储藏)的文件

git stash list 显示stash的所有变更

git stash drop 丢弃最近一次stash的变更

git cherry-pick

git cherry-pick master 应用主分支顶部提交引入的更改,并使用此更改创建新的提交

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值