git版本控制工具学习笔记
2016-02-23 17:09
573 查看
学习资源来自github官网及廖雪峰教程
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
暂存区概念:
把文件往Git版本库里添加的时候,是分两步执行的:
第一步是用git add把文件添加进去,实际上就是把文件修改添加到暂存区;
第二步是用git commit提交更改,实际上就是把暂存区的所有内容提交到当前分支。
实际上提交的是原来的某文件,并非当前工作目录中的某文件
可以再次:
可以在用户主目录里找到.ssh目录,里面有
这两个就是SSH Key的秘钥对,id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以放心地告诉任何人。
2、登陆GitHub,打开“Account settings”,“SSH Keys”页面, 然后,点“Add SSH Key”。
填上任意Title,在Key文本框里粘贴id_rsa.pub文件的内容:
新建一个
本地 learngit目录下执行
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
git基本命令
git add file提交文件
git commit -m "what changes"提交更改信息注释
git status查看修改状态
git log查看日志
git log --pretty=oneline一行显示日志信息
git reset --hard HEAD^版本回退到上一个版本
git reset --hard xxxx(某版本号前几位)回退到
xxxx版本
git reflog用来记录你的每一次命令
暂存区概念:
把文件往Git版本库里添加的时候,是分两步执行的:
第一步是用git add把文件添加进去,实际上就是把文件修改添加到暂存区;
第二步是用git commit提交更改,实际上就是把暂存区的所有内容提交到当前分支。
git add 某文件 vim 某文件 git commit -m "add 某文件"
实际上提交的是原来的某文件,并非当前工作目录中的某文件
可以再次:
git add 某文件 git commit -m "add 某文件"进行提交新的某文件
git checkout -- file 放弃工作区的最近一次修改 git reset HEAD file 把暂存区的修改撤销掉 git rm file 删除file文件 git commit -m "remove file"
远程仓库
1、创建SSH Key$ ssh-keygen -t rsa -C "youremail@example.com"
可以在用户主目录里找到.ssh目录,里面有
id_rsa和
id_rsa.pub两个文件。
这两个就是SSH Key的秘钥对,id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以放心地告诉任何人。
2、登陆GitHub,打开“Account settings”,“SSH Keys”页面, 然后,点“Add SSH Key”。
填上任意Title,在Key文本框里粘贴id_rsa.pub文件的内容:
新建一个
repository
本地 learngit目录下执行
git remote add origin https://github.com/lesliefish/learngit.git[/code]
把本地内容推送至远程库:yu@ubuntu:~/Linux/223/learngit$ git push -u origin master Username for 'https://github.com': leslie Password for 'https://leslie@github.com':
把本地库的内容推送到远程,用git push命令,实际上是把当前分支master推送到远程。
推送最新修改yu@ubuntu:~/Linux/223/learngit$ git push origin master Username for 'https://github.com': lesliefish Password for 'https://lesliefish@github.com': Everything up-to-date
每次本地提交后,只要有必要,就可以使用命令git push origin master推送最新修改;
远程库克隆到本地git clone https://github.com/lesliefish/gitskills[/code]分支
创建分支devyu@ubuntu:~/Linux/223/learngit$ git checkout -b dev Switched to a new branch 'dev' yu@ubuntu:~/Linux/223/learngit$ git branch * dev master
修改readme.txt后提交yu@ubuntu:~/Linux/223/learngit$ vim readme.txt yu@ubuntu:~/Linux/223/learngit$ git add readme.txt yu@ubuntu:~/Linux/223/learngit$ git commit -m "branch test" [dev af18f3f] branch test 1 file changed, 1 insertion(+)
此时修改的readme.txt只是分支上的readme.txt
切换回master分支发现本里readme.txt内容并未改变yu@ubuntu:~/Linux/223/learngit$ git checkout master Switched to branch 'master' Your branch is up-to-date with 'origin/master'. yu@ubuntu:~/Linux/223/learngit$ cat readme.txt
合并分支到master上git merge devyu@ubuntu:~/Linux/223/learngit$ git merge dev Updating ee8f6f3..af18f3f Fast-forward readme.txt | 1 + 1 file changed, 1 insertion(+)
删除分支,删除后查看分支,发现只有master分支了yu@ubuntu:~/Linux/223/learngit$ git branch -d dev Deleted branch dev (was af18f3f). yu@ubuntu:~/Linux/223/learngit$ git branch * master
bug分支
Git还提供了一个stash功能,可以把当前工作现场“储藏”起来,等以后恢复现场后继续工作
多人协作
查看远程库的信息,用git remote:yu@ubuntu:~/Linux/223/learngit$ git remote origin yu@ubuntu:~/Linux/223/learngit$ git remote -v origin https://github.com/lesliefish/learngit.git (fetch) origin https://github.com/lesliefish/learngit.git (push)标签
yu@ubuntu:~/Linux/223/learngit$ git tag v1.0 yu@ubuntu:~/Linux/223/learngit$ git tag v1.0
找到历史提交的commit idyu@ubuntu:~/Linux/223/learngit$ git log --pretty=oneline --abbrev-commit af18f3f branch test ee8f6f3 new gitskills lib b42f322 remove test.txt 7d35956 add test.txt 0995552 2ci tijiao readme.txt 3521dac git tracks changes 3421d8b how stage works 142ea61 append GPL 2a3df4e add distributed in readme.txt 17c026f new file readme.txt
对add test.txt这次提交打标签:yu@ubuntu:~/Linux/223/learngit$ git tag v0.8 7d35956 yu@ubuntu:~/Linux/223/learngit$ git tag v0.8 v1.0
查看标签git show:yu@ubuntu:~/Linux/223/learngit$ git show v0.8 commit 7d3595652ac527edcfe561ae613fe286a39ad389 Author: lesliefish <yuleics@outlook.com> Date: Tue Feb 23 15:11:39 2016 +0800 add test.txt diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..95160f9 --- /dev/null +++ b/test.txt @@ -0,0 +1 @@ +wei he zhe me diao
删除本地标签yu@ubuntu:~/Linux/223/learngit$ git tag -d v0.8 Deleted tag 'v0.8' (was 7d35956)
如果标签已经推送到远程,要删除远程标签就麻烦一点,先从本地删除:git tag -d v0.9
然后远程删除:git push origin :refs/tags/<tagname>
相关文章推荐
- 内核通知链原理及机制
- delphiXE调用Objective-c库
- JSP简单练习-获取表单数据
- __all__有趣的属性
- spring多数据源的处理 mybatis实现跨库查询
- css之!important 及display:inline 及clear:both
- iOS手势(滑动)返回的实现(自定义返回按钮)
- oracle 查看用户表数目,表大小,视图数目等
- Leetcode--179--Largest Number
- 互联网+时代的7个引爆点(读书笔记)
- Animation动画详解(五)——ValueAnimator高级进阶(一)
- Android Fragment 真正的完全解析(上)——张鸿洋老师
- 1018. 锤子剪刀布 (20)
- 关于iOS7里的JavaScriptCore framework
- ios pathForResource函数返回空值
- Linux_DHCP篇
- jQuery循环table里面的每一条数据
- 【第三章】 DI 之 3.1 DI的配置使用 ——跟我学spring3
- behemoth - 00
- HDU 1329 Hanoi Tower Troubles Again!