git基础实践
Git 是 Linus Torvalds为了帮助管理Linux内核开发而开发的一个开放源码的版本控制软件。
git常用命令
列出当前配置
git config --list
列出repository配置
git config --local --list
列出全局配置
git config --global --list
列出系统配置
git config --system --list
配置用户名
git config --global user.name "your name"
配置用户邮箱
git config --global user.email "youremail@github.com"
配置git命令输出为彩色
git config --global color.ui auto
查看当前工作区的所有文件的状态
git status
查看提交历史:
git log
参数-p展开每次提交的内容差异,如-2显示最近的两次更新
git log -p -2;
提交工作区所有文件到暂存区
git add .
删除工作区文件并且也从暂存区删除对应文件的记录
git rm
比较工作区中当前文件和暂存区之间的差异
git diff
隐藏当前变更
git stash
查看当前所有的储藏
git stash list
应用最新的储藏
git stash apply
将暂存区中的文件提交到本地仓库
git commit -m "commit_info"
将所有已经使用git管理过的文件暂存并提交,相当于执行git add和git commit
git commit -a -m "commit_info"
撤销上一次提交
git commit --amend
比较暂存区与上一版本的差异
git diff --cached
指定文件在暂存区和本地仓库的不同
git diff
列出现在所有的标签
git tag
使用特定的搜索模式列出符合条件的标签
git tag -l "v1.*"
创建一个含附注类型的标签,加-a参数
git tag -a v1.4 -m "my version 1.4"
使用git show命令查看相应标签的版本信息
git show v2.0
将标签推送到远程仓库中
git push origin
eg: git push origin v2.0
将本地所有的标签全部推送到远程仓库中:
git push origin --tags
创建分支
git branch
切换分支
git checkout
创建并切换到分支
git checkout -b
删除分支
git branch -d
将当前分支与指定分支进行合并
git merge
显示本地仓库的所有分支
git branch
显示各个分支最新一次提交对象的信息
git branch -v
查看哪些分支已经合并到了当前分支
git branch --merged
查看哪些分支还没有合并到当前分支
git branch --no-merged
把远程分支合并到当前分支
git merge
eg:
git merge origin/devel
在远程分支的基础上创建新的本地分支(跟踪分支)
git checkout -b
eg:
git checkout -b devel orgin/devel
查看本地仓库关联的远程仓库,-v参数会显示远程仓库的url地址
git remote
git remote -v
添加远程仓库
git remote add
eg:
git remote add blog https://github.com/blog/blog.git
从远程仓库中拉取更新
git fetch
git fetch origin
git fetch 只会讲远端数据拉到本地仓库,并不会自动合并到当前工作分支,需要人为合并,如果设置了某个分支关联到远程仓库的某个分支可以使用git pull来拉取远程分支的数据自动合并到当前分支;
将本地仓库分支推送到远程仓库
git push
git push origin master
将本地分支推送到远程仓库不同名分支
git push
删除远程分支(本地内容为空)
git push
git push origin
查看远程仓库的详细信息
git remote show origin
修改远程仓库在本地的简称
git remote rename
git remote rename origin ori
移除远程仓库
git remote rm
git clone 指定分支:
git clone -b stable-2.2 https://github.com/ansible/ansible-modules-core.git
git 回滚版本
git reset --hard sha
git push origin HEAD --force
合并到主分支
git rebase和git merge的区别
常见报错处理
报错内容
fatal: unable to access 'https://github.com/xxxx/xxxx.github.io.git/': SSL certificate problem: self signed certificate in certificate chain
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Error: fatal: unable to access 'https://github.com/xxxx/xxxx.github.io.git/': SSL certificate problem: self signed certificate in certificate chain
at ChildProcess.
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at ChildProcess.cp.emit (H:\hexo-Blog\node_modules\cross-spawn\lib\enoent.js:40:29)
at maybeClose (internal/child_process.js:925:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
解决方法
git config --global http.sslVerify false
报错内容
Cloning into 'jplot'...
fatal: unable to access 'https://github.com/rs/jplot.git/': Peer certificate cannot be authenticated with known CA certificates
解决方法
git config --global http.sslVerify false
.gitigore不生效
.gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。
解决方法就是先把本地缓存删除(改变成未track状态)
git rm -r --cached .
git add .
git commit -m 'update .gitignore
.gitginore规则示例
注释内容 井号开头为注释内容
.md # 忽略所有 .md 结尾的文件
!readme.md # 但 readme.md 除外
/TODO # 仅仅忽略项目根目录下的 TODO 文件,不包括 source/TODO
node_modules/ # 忽略 node_modules/ 目录下的所有文件
public/.html # 会忽略 public/index.html 但不包括 public/2019/index.html
本文来自博客园,作者:寻月隐君,转载请注明原文链接:https://www.cnblogs.com/QiaoPengjun/articles/15947266.html

浙公网安备 33010602011771号