Git 安装及使用小结
2024-08-13 21:30:04 217人阅读
Git 安装及使用小结<style>a:focus { outline: thin dotted #333; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2px;}a:hover { outline: 0;}a:active { outline: 0;}a:hover { color: #005580 !important; text-decoration: underline !important;}blockquote small:before { content: ‘\2014 \00A0‘;}q:before { content: "";}q:after { content: "";}blockquote:before { content: "";}blockquote:after { content: "";}.hljs-folder:before { top: 0; content: ‘‘; width: 14px; height: 12px; margin-top: 0px; margin-right: 3px; position: relative; display: inline-block; background-size: 14px; background-repeat: no-repeat;}.hljs-file:before { top: 0; content: ‘‘; width: 14px; height: 12px; margin-top: 0px; margin-right: 3px; position: relative; display: inline-block; background-size: 14px; background-repeat: no-repeat;}.hljs-hiddenfile:before { top: 0; content: ‘‘; width: 14px; height: 12px; margin-top: 0px; margin-right: 3px; position: relative; display: inline-block; background-size: 14px; background-repeat: no-repeat;}.hljs-file:before { height: 14px; margin-left: 1px;}.hljs-hiddenfile:before { height: 14px; margin-left: 1px;}.hljs-file.photo:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c5";}.hljs-file.plain:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f016";}.hljs-file.source:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c9";}.hljs-file.archive:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c6";}.hljs-file.audio:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c7";}.hljs-file.video:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c8";}.hljs-file.pdf:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c1";}.hljs-file.xls:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c3";}.hljs-file.doc:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c2";}.hljs-file.ppt:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c4";}.hljs-folder:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f114";}.hljs-hiddenfile:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f016";}.li_linenum:before { content: counter(lines , decimal); position: absolute; left: 0px; text-align: center; width: 2.5em; opacity: 0.5; vertical-align: top;}</style><style>a:focus { outline: thin dotted #333; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2px;}a:hover { outline: 0;}a:active { outline: 0;}a:hover { color: #005580 !important; text-decoration: underline !important;}blockquote small:before { content: ‘\2014 \00A0‘;}q:before { content: "";}q:after { content: "";}blockquote:before { content: "";}blockquote:after { content: "";}.hljs-folder:before { top: 0; content: ‘‘; width: 14px; height: 12px; margin-top: 0px; margin-right: 3px; position: relative; display: inline-block; background-size: 14px; background-repeat: no-repeat;}.hljs-file:before { top: 0; content: ‘‘; width: 14px; height: 12px; margin-top: 0px; margin-right: 3px; position: relative; display: inline-block; background-size: 14px; background-repeat: no-repeat;}.hljs-hiddenfile:before { top: 0; content: ‘‘; width: 14px; height: 12px; margin-top: 0px; margin-right: 3px; position: relative; display: inline-block; background-size: 14px; background-repeat: no-repeat;}.hljs-file:before { height: 14px; margin-left: 1px;}.hljs-hiddenfile:before { height: 14px; margin-left: 1px;}.hljs-file.photo:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c5";}.hljs-file.plain:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f016";}.hljs-file.source:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c9";}.hljs-file.archive:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c6";}.hljs-file.audio:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c7";}.hljs-file.video:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c8";}.hljs-file.pdf:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c1";}.hljs-file.xls:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c3";}.hljs-file.doc:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c2";}.hljs-file.ppt:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f1c4";}.hljs-folder:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f114";}.hljs-hiddenfile:before { font: normal normal normal 14px / 1 FontAwesome; content: "\f016";}.li_linenum:before { content: counter(lines , decimal); position: absolute; left: 0px; text-align: center; width: 2.5em; opacity: 0.5; vertical-align: top;}</style> Git 安装及使用小结Git安装与配置
Linux下安装与配置
通过命令行 sudo apt-get install git
进行安装
配置 git config --global user.name "xxx"
, git config --global user.email "xxx@xxx.com"
(global 选项可选)
使用 git push到github时,需要在github上添加本机的SSH key
生成SSH Key: ssh-keygen -t rsa -C "xxx@xxx.com"
(按三个回车即可,一般不使用密码)
生成的key在 ~/.ssh
目录下,该目录下包含两个文件: id_ras
(私钥), id_rsa.pub
(公钥)
添加私钥:ssh-add id_rsa
在github上添加ssh key. 在 setting->SSH and GPG Keys下添加 id_ras.pub
中内容
windows下安装与配置
直接下载安装 git
配置与linux 下类似
说明: git config命令的--global参数,用了这个参数,表示你这台机器上所有的Git仓库都会使用这个配置,当然也可以对某个仓库指定不同的用户名和Email地址.
常见操作命令
创建版本库
git init
: 创建版本库
git add .
: 添加文件到版本库,“.”表示目录下所有文件,也可通过文件名或目录指定
git rm xxx
: 从版本库中删除一个文件
git commit -m "xxx"
: 提交文件,-m选项表示的示提交说明
查看文件改动
git status
: 查看工作区文件变动情况,显示那些文件被修改过
git diff xxx
: 查看文件xxx的修改内容
gitk
: 图形化界面各版本修改情况
版本回退
git log
: 查看提交历史,由近到远排列,git log --pretty=oneline
简化输出信息
git reset --hard xxx
: xxx 为 commit id,回退到指定commit id 的版本
git reflog
: 查看历史命令,以便确定回到未来哪个版本
撤销单个文件的修改
若文件没有执行 add 操作
git checkout -- xxx
: 直接丢弃工作区文件xxx的修改
若文件执行过add 操作, 需执行两步
git reset HEAD xxx
--> git checkout -- xxx
关联远程仓库与本地仓库
首先需要在github中手动新建分支
一种方式是将分支 clone 到本地,进行修改,然后提交。
git clone git@github.com:username/RepositoryName.git
另一种方式是,讲本地已有仓库与之关联。
git remote add origin git@github.com:username/RepositoryName.git
提交本地库内容到远程库
git push -u origin master
: 将当前master分支推送当远程分支origin, -u
参数,表示将本地master分支与远程的origin分支关联起来,在以后的推送或者拉取时,可以简化命令git push origin master
(附件: markdownFile.md)
来自为知笔记(Wiz)
Git 安装及使用小结
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉:
投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。