Git 常见命令的使用

来源:互联网 发布:瑞士莲 费列罗 知乎 编辑:程序博客网 时间:2024/06/06 05:03

ssh-key

//1.生成ssh-key(在用户家目录.ssh文件下)ssh-keygen -t rsa -C "Z-Beatles@waynechu.cn"//2.重命名ssh-keycp ~/.ssh/id_rsa.pub ~/.ssh/Z-Beatles@waynechu.cn.pub//3.添加public key到github

init repo

cd 'repo'//本地初始化仓库git init//创建远程仓库git remote add origin git@github.com:Z-Beatles/reponame.git//把文件添加到暂存区git add .//把暂存区内容提交到当前分支git commit -m "reason"//推送到远程服务器git push origin master

clone repo

//Clone with SSHgit@github.com:Z-Beatles/MobileSafe.git//Clone with HTTPShttps://github.com/Z-Beatles/MobileSafe.git

分支管理 branch

//查看分支git branch//创建分支git branch 'newbranch'//切换分支git chechout 'branchname'//创建并切换到该分支git checkout –b 'branchname'//合并某分支到当前分支git merge 'branchname'//删除分支git branch -d 'branchname'//强制删除某个分支 (未被合并的分支被删除的时候需要强制)git branc -D 'branchname'

查看文件 diff

//比较当前文件和暂存区文件差异git diff <file>//比较两次提交之间的差异git diff <id1><id1><id2>//在两个分支之间比较git diff <branch1>..<branch2>//比较暂存区和版本库差异(默认)git diff --staged//比较暂存区和版本库差异git diff --cached//仅仅比较统计信息git diff --stat

暂存管理 stash

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

Git远程仓库管理

//查看远程服务器地址和仓库名称git remote -v //查看远程服务器仓库状态git remote show origin//添加远程仓库地址git remote add origin git@github.com:Z-Beatles/reponame.git//设置远程仓库地址 (用于修改远程仓库地址)git remote set-url origin git@github.com:Z-Beatles/reponame.git//删除远程仓库git remote rm <repository>
0 0
原创粉丝点击