配置级别:
local 【默认,高优先级】:只影响本仓库
global【中优先级】:影响到所有当前用户的git仓库
system【低优先级】:影响到全系统的git仓库
注:中文支持git config --global core.quotepath false当然是不建议中文的啦
一、初始化仓库
git init
二、git status
三、git add 添加文件内容到在暂存区(同时文件被跟踪【红色】)touch README.md创建一个文件
git add . 批量添加到暂存区
git rm --cached :仅从暂存区删除
git rm :从暂存区与工作目录删除
git rm $(git ls -fules -- deleted) :删除所有被跟踪,但是在工作目录中被删除的文件git
.gitignore 在添加时忽略匹配的文件,仅作用于未追踪的文件【需要在配置文件里面写】
暂存区是绿色的
四、提交 git commit -m "提示信息"
也可以直接从工作目录直接提交git commit -a -m "提示信息"
git log查看提交历史
git log --oneline 显示短的 校验和,并与提交描述显示在同一行
git log --color --graph --pretty=format 这个不是很懂,先记下来
=================================================================================
git diff 比较2个版本的差异
git diff -cached [<reference>] 暂存区与某次提交差异,默认为HEAD
git diff -cached [<reference>] 工作目录与某次提交的差异
撤销本地修改 !慎重使用
git checkout -- README.md
撤销暂存区内容
git reset HEAD README.md
==========================================================
分支的操作
git branch <branchName>创建一个分支
git branch -d <branchName>删除指定的分支
git branch -v 显示现在所有分支信息
git commit
/*通过移动HEAD检出版本,可用于分支切换*/
git checkout <branchName>
git checkout -b <branchName>
git checkout <reference>
git checkout next
git checkout -恢复到上个分支
git checkout -b issue-26(分支名)
git branch -v查看所有分支
git reset /*将当前分支回退到历史某个版本*/
git reset --mixed <commit>(默认)(例e390b3)
git reset --soft<commit>
git reset --hard<commit>
git reflog 查看所有分支的所有操作记录(包括已经被删除的 commit 记录和 reset 的操作)
回退版本
================================================================================
git stash 保存目前的工作目录和暂存区状态,并返回到干净的工作空间
除工作目录和暂存区还有相当于一个栈
git stash save "信息"
git stash list查看存了多少stash暂存
git stash apply stash@{0}将暂存恢复到工作区
git stash drop stash@{0}将记录从stash区删除
stash pop = stash apply apply + stash drop
=====================================================================================
合并分支
git merge
git merge next
git cat -file -p HEAD
解决merge冲突
git merge next master
git merge next --no-ff/*不使用fast-forward方式分支合并*/
git status/*both modified都做了修改的意思*/
=======================================================================
变基git rebase 修改提交历史基线千万不要在公有分支上使用rebase
git rebase master
git rebase --onto master 5751363
git tag对某个提交设置一个不变的别名
git tag v1.0 e39d0b2
===============================================================
1连接远程服务器
git init ~/git - server --初始化?
git push origin master推送到远程仓库/*![rejected]有人先于你提交了,先同步代码再提交*/
git remote add origin ~/git-server添加一个远程仓库别名
git remote -v 查看远程仓库信息
git fetch origin master获取远程仓库提交历史
git merge origin/master
git push origin master
git pull = git fetch+git merge
2完整获取远程仓库
git clone ~/git-server test222【~第一个参数是远程仓库地址】【git-server第二个参数是文件名】【第三个参数是目录名】
git remote -v
http://rogerdudler.github.io/git-guide/index.zh.html git简明指南
http://try.github.io/git简单使用视频
https://git-scm.com/book/zh/v1/一本书
==================================================================
1.告诉git用户名:
git config --global user.name 'lufeijun12138'
git config --global user.email '[email protected]'
2.初始化
git init
3.查看目录
ls
4.添加文件到git仓库
git add 1.html 添加1.html
git add . 添加修改文件到仓库
git add -all -all添加所有文件
5.查看状态
git status
6.提交到本地仓库
git commit -m '增删改查加分页'
7.关联远程仓库,没报错就是对了,后边的https是你git官网SSH后面的地址
git remote add origin https://github.com/lufeijun12138/gz_911.git
8.提交到远程仓库
git push -u https://github.com/lufeijun12138/gz_911.git
或者
git push -u origin(这是你的别名) master:master
然后填写你的用户名和密码就好了
git下载自己项目到本地
假如外出工作,需要在另一台电脑上面pull自己的某个git远程项目到本地
$ git init
$ git pull 你仓库的网址
后面这部分就是自己项目的网址,我这里是pull了我的项目54qjLogin
$ git pull 你仓库的网址
如果下载的这个项目更改后需要push的会出现:
$ git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using
git remote add <name> <url>
and then push using the remote name
git push <name>
这个时候第一次push需要网址:
$ git add --all
$ git commit -m "TTyb"
$ git remote add origin https://github.com/TTyb/54qjLogin
$ git push -u origin master
然后下一次就不用那么麻烦了,直接:
$ git add --all
$ git commit -m "TTyb"
$ git push