Git 的安装
@[TOC](Git 的安装) Git 的安装很好用的一段命令基本命令git ssh 与 https 互换本地仓库关联远程仓库结构图Git用了一段时间后再用SVN的赶脚
Git 的安装
Windows安装软件,百度云盘地址:链接:
https://pan.baidu.com/s/1LoLybxGb_evTZUOoWkZhHw 密码:xwv5
Linux安装:。。。
Mac安装:。。。
很好用的一段命令
Git 全局设置:
git config --global user.name "Young"
git config --global user.email "young_smith@163.com"
创建 git 仓库:
mkdir YoungSmith
cd YoungSmith
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin git@gitee.com:YoungSmith/YoungSmith.git
git push -u origin master
已有项目?
cd existing_git_repo
git remote add origin git@gitee.com:YoungSmith/YoungSmith.git
git push -u origin master
基本命令
git --version
git config [--global] 这里需要说明一下:git config 命令用于Git配置变量。
其中 git config 版本库级别的配置文件
git config --global 全局配置文件
git config --global user.name "YoungSmiths"
git config --system 系统级别配置文件
可以通过git config -e --global 查看配置文件内容
git config user.name 查看全局配置
git config --unset --global user.name 删除全局配置
git init 初始化。例如:git init demo 或 cd demo
git grep 搜索文本
git add .
git status [-s] 状态 -s 简版状态
git commit -m "describe" 提交
git rev-parse --git-dir 显示版本库.git目录所在位置
git rev-parse --show-otplevel 显示工作去目录
git rev-parse --show-prefix 显示相对于工作区的相对目录
格式化查看日志,graph关系图,stat 日志记录统计
git commit --allow-empty -m "describe" 允许无用户提交
git config --global alias.ci "commit -s" 命令别名(未验证成功)
git clone a b 克隆(未验证成功)
git diff 工作区和提交任务(提交暂存区,stage)中相比较
git diff HEAD 工作去和HEAD(当前分支)作比较
git diff --catched/staged 提交暂存区(提交任务,stage)和版本库比较
git reset HEAD 暂存区的目录会被重写,会被当前分支替换,但是对工作区没有影响。
git rm --cached <file> 直接从暂存区删除文件,工作区没有影响
git checkout . 或者git checkout -- <file>
暂存区全部文件或指定文件替换工作去文件,危险行为,会清楚工作区中没有提交的改变。
指向的分支中的全部代码替换暂存区和工作去中的文件,极其危险,会清楚未提交的代码。
git stash
git reflog show master | head -5 显示提交的五次记录
git ssh 与 https 互换
我的情况是原本使用ssh,但是ssh突然使用不了,需要跟换https 步骤:
修改远程仓库地址 方法有三种: 1.修改命令
git remote set-url origin [url]
我这里使用 git remote set-url origin [url]命令,直接修改远程仓库为https的地址 2.先删后加
git remote rm origin git remote add origin [url]
3.直接修改config文件 2)以上进行git操作的时候,每次都需要密码,所以可以配置免密 1)新建文件并保存密码
$ touch ~/.git-credentials $ vim ~/.git-credentials
2)添加内容
https://{username}:{passwd}@github.com
3)添加git配置
$ git config --global credential.helper store
如果想切回ssh,直接修改远程仓库的地址即可 例如:git remote set-url origin [ssh的url]
本地仓库关联远程仓库
git remote add origin https://github.com/YoungSmiths/Test.git
git reset --hard master@{2}
git reset 重置命令,最危险最容易误用
用法一:git reset [-q] [<commit>] [--] <path> ...
用法二:git reset [--soft | --mixed | --hard | --merge | --keep] [-q] [<commit>]
echo "hello." > test.txt
克隆GitHub上的项目:git clone
结构图
图一 图二
https://github.com/YoungSmiths/YoungSmiths.github.io.git
Git用了一段时间后再用SVN的赶脚
换了一家公司,版本管理用的是SVN,才发现Git是简直就是太方便了,现在用SVN感觉特别蹩脚,原理性的概念不多说,网上一堆。对于实际开发来说,SVN基本上是一个功能开一个分支,当然Git也基本如此。但是实际情况是这样的,项目组的SVN服务器不怎么好使,时不时关机什么的,提交一次代码要和领导说一次,也不好意思经常麻烦领导,就一次提交代码实现多个小功能,很多代码,这样一来就很容易乱了,基本上为了清楚一点只能是手动在代码上打标签。如果是GIt的话就不一样了,我本地有一个分支,将代码提交到本地分支,甚至可以创建另外一个bug分支等等,和主分支服务器连不连得上基本没有影响。 当然,Git的好处不只是这一点,这只是项目中碰到的一种情况,其中辛酸苦与泪,经历过就知道了,最好不要经历,哈哈哈哈。。。 —— —— 2018.2.3
转载请注明原文地址: https://ju.6miu.com/read-1299394.html