Git-Notes
1.Git安装,直接在官网下载安装即可。
2.Git配置,使用config选项,配置名字和邮箱,如下所示
C:\Users\1yyg>git config --global user.name "zhumuxian" C:\Users\1yyg>git config --global user.email "495472831@qq.com"
3.创建仓库,使用init选项
F:\webim>git init
Initialized empty Git repository in F:/webim/.git/
4.添加文件和提交,使用add和commit选项
F:\webim>git add index.js //将文件添加到暂存区 F:\webim>git commit -m "add index.js" //提交到master分支
[master 92d277f] add index.js
file changed, insertions(+)
create mode index.js
5.查看仓库当前状态,使用status选项
F:\webim>git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory) modified: index.js
6.对比当前版本文件和上个版本文件的差异,使用diff选项
F:\webim>git diff index.js
diff --git a/index.js b/index.js
index 06d9b64..0c6787e
--- a/index.js
+++ b/index.js
@@ -, +, @@ $(function(){ var originDemension = {}; +
+
var videoExtReg = /^\.(?=mpg|3gp|vob|rmvb|mov|flv|avi|wmv|mp4|mkv)/i,
musicExtReg = /^\.(?=flac|ape|wav|mp3|aac|ogg|wma)/i,
wordExtReg = /^\.(?=doc|docx)/i;
7.对于修改过的文件,再次使用add,commit命令提交即可
8.查看仓库提交日志,使用log选项,搭配--pretty=oneline更清晰
F:\webim>git log --pretty=oneline
973ef9dcb5c4cc3de12fa4e3668a16ff3adb2992 add nihao
c8fbe43e78d3155262e427aa1df246156563cf23 add license.txt
de0edd4c3fc56fdb74fd87ca9dfa0acb82847faa index.js
92d277f2dbe720179530962b11d785c448c5296a add index.js
5954ab28619985ab0ad768602578466dc92399fd del index.js
cc4370f6424daf34c34f9b90196ab56857d61f47 add index.js
9.撤销版本,使用reset选项
git reset --hard HEAD^ //HEAD^后面必须跟一个空格,HEAD代表当前版本,HEAD^当前版本的上个版本,一次类推,也可以使用HEAD~[0-9..]来代替 git reset --hard commit_id //使用commitId来撤销提交,commitId可以使用git log后者 git reflog来查看
10.查看所有命令,使用reflog选项
F:\webim>git reflog
973ef9d HEAD@{}: reset: moving to HEAD^
78ae302 HEAD@{}: reset: moving to HEAD
78ae302 HEAD@{}: reset: moving to HEAD
78ae302 HEAD@{}: commit: add heheda again
973ef9d HEAD@{}: reset: moving to HEAD~
9fb4130 HEAD@{}: commit: add heheda
973ef9d HEAD@{}: commit: add nihao
c8fbe43 HEAD@{}: commit: add license.txt
de0edd4 HEAD@{}: commit: index.js
92d277f HEAD@{}: commit: add index.js
5954ab2 HEAD@{}: commit: del index.js
cc4370f HEAD@{}: commit (initial): add index.js
11.撤销修改
情况一:工作区中的内容修改了,但是没有添加到暂存区,可以利用checkout -- file来撤销改动
F:\webim>git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory) modified: license.txt F:\webim>git checkout -- license.txt F:\webim>git status
On branch master 情况二:
工作区的改动添加进了暂存区,但是没有提交,可以利用reset HEAD file来撤销修改,然后在使用git checkout -- file来恢复
F:\webim>git reset HEAD license.txt
Unstaged changes after reset:
M license.txt
F:\webim>git checkout -- license.txt
12.删除文件,使用rm选项,然后commit提交即可
F:\webim>git rm license.txt
rm 'license.txt'
F:\webim>git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage) deleted: license.txt F:\webim>git commit -m "del license file"
[master 5c258d3] del license file
file changed, deletions(-)
delete mode license.txt
13.添加远程仓库
由于没有自己的git服务器,这里使用github的服务,首先创建ssh key,采用rsa加密,主要是github用来确认推送者的身份,如下所示
$ ssh-keygen -t rsa -C "495472831@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/1yyg/.ssh/id_rsa):
Created directory '/c/Users/1yyg/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/1yyg/.ssh/id_rsa.
Your public key has been saved in /c/Users/1yyg/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:jDCsKX+gz2uoiLMYoBuphe7bK7KH4hTgsDkb3N6Gnks @qq.com
然后将id_rsa.pub的内容复制到github网站个人设置里面的new ssh key中。接着使用git remote add添加远程库,该库必须在github中存在
F:\webim>git remote add webim https://github.com/zhu495472831/webim.git
接着在推送内容分支内容之前,使用git pull 先拉取最新的内容
F:\webim>git pull webim master
//如果遇到fatal: refusing to merge unrelated histories错误,可以添加 --allow-unrelated-histories选项解决
F:\webim>git pull webim master --allow-unrelated-histories
然后就可以推送内容了
F:\webim>git push webim master
Counting objects: , done.
Delta compression using up to threads.
Compressing objects: % (/), done.
Writing objects: % (/), 3.20 KiB | bytes/s, done.
Total (delta ), reused (delta )
To https://github.com/zhu495472831/webim.git
ef0c6db..1e4b6fa master -> master
14.克隆仓库,使用git clone
F:\zmx\gittest>git clone git@github.com:zhu495472831/webim.git
Cloning into 'webim'...
The authenticity of host 'github.com (192.30.253.112)' can't be establ
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the li
n hosts.
remote: Counting objects: , done.
remote: Compressing objects: % (/), done.
remote: Total (delta ), reused (delta ), pack-reused 0R
% (/)
Receiving objects: % (/), 12.45 KiB | bytes/s, done.
Resolving deltas: % (/), done.
15.分支,分支有利于多人协同作业
创建分支git branch name或者git checkout -b name创建并切换,查看分支git branch,切换分支git checkout branchName,删除分支git branch -d
F:\webim>git branch
* master F:\webim>git branch dev F:\webim>git branch
dev
* master F:\webim>git checkout dev
Switched to branch 'dev' F:\webim>git branch
* dev
master
删除分支
F:\webim>git branch dev2 F:\webim>git branch
* dev
dev2
master F:\webim>git branch -d dev2
Deleted branch dev2 (was 1e4b6fa). F:\webim>git branch
* dev
master
在创建分支之后,在分支上对文件进行的操作,别的分支感知不到,可以使用merge合并分支,便可以
F:\webim>git merge dev
Updating 346ce30..d17e615
Fast-forward
hello.txt | ++-
file changed, insertions(+), deletion(-)
在合并分支的时候,可以指定--no-ff参数,表示禁用fast forward模式,这样在合并分支之后,删除分支时,分支的信息就不会丢失
F:\webim>git merge --no-ff -m "merge dev width no-ff" dev
Merge made by the 'recursive' strategy.
hello.txt | ++-
file changed, insertions(+), deletion(-)
16.存储现场,当在一个分支上进行开发的时,来了一个优先级更高的bug需要修复,这时不想提交未完成的代码,就可以使用stash命令来保存现场
F:\webim>git stash list
stash@{}: On dev: hello.txt F:\webim>git stash pop
On branch dev
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory) modified: hello.txt
git stash 保存 git stash save [message] 保存并备注 git stash list查看所有stash git stash clear清空所有stash git stash apply stash@{n} 还原某个stash git stash pop还原最近的一次stash
17 查看绑定的远程仓库信息
F:\webim>git remote -v
webim https://github.com/zhu495472831/webim.git (fetch)
webim https://github.com/zhu495472831/webim.git (push)
18 创建和远程分支关联的分支
F:\webim>git checkout -b dev webim/dev
Branch dev set up to track remote branch dev from webim.
Switched to a new branch 'dev'
//也可以使用branch --track或--set-upstream-to关联
F:\webim>git branch --set-upstream dev webim/dev
The --set-upstream flag is deprecated and will be removed. Consider using --trac
k or --set-upstream-to
Branch dev set up to track remote branch dev from webim.
19 从远程库拉取内容
F:\webim>git pull
Already up-to-date.
20 打标签,使用tag命令
git tag:查看当前分支所有tag
git tag name:创建标签name,还可以指定commitid,例如git tag v1.0 63cbab46a467236a290fd4fb56439755f83ac49e,另外可以为标签加上描述,如git tag v1.0 -a -m "release 1.0"
git show tag_name:查看某个标签的详细信息
F:\webim>git tag v1. F:\webim>git tag
v1. F:\webim>git show v1.
commit 63cbab46a467236a290fd4fb56439755f83ac49e
Author: zhumuxian <@qq.com>
Date: Fri Oct :: + add nizhidema diff --git a/hello.txt b/hello.txt
index 8ef3fc0..09f6427
--- a/hello.txt
+++ b/hello.txt
@@ -, +, @@
hello world
-this is a worla <A3><A1><A3><A1>
\ No newline at end of file
+this is a worla <A3><A1><A3><A1>
+<C4><E3>ֵ<B5><C3><C2><F0>
\ No newline at end of file
21 忽略文件,通过使用.gitignore文件配置,在git根目录新建一个名为.gitignore的文件,然后推送到github,内容如下所示
#images
*.jpg
*.png
*.gif
*.swf
*.html
22 配置别名,使用git config alias命令配置命令的别名
使用命令配置如下
F:\webim>git config --global alias.st status
F:\webim>git st
On branch master
Your branch is up-to-date with 'webim/master'.
nothing to commit, working tree clean
Git-Notes的更多相关文章
- git notes的使用
1. 获取notes git fetch origin refs/notes/*:refs/notes/* 2. 设置notes 2.1 git config --add core.notesRef ...
- git notes的用法
1. notes翻译为中文评注 2. notes出现的作用 避免某一次commit的内容修改导致当前以及随后的commit发生变化,相当于在当前的commit后面追加一些信息,如: 某次commit的 ...
- git如何将旧commit的相关notes复制到新commit?
答: git notes copy <old-commit> <new-commit>
- 常look的Git命令
常用的Git命令 命令 简要说明 git add 添加至暂存区 git add–interactive 交互式添加 git apply 应用补丁 git am 应用邮件格式补丁 git a ...
- Git命令详解
一个中文git手册:http://progit.org/book/zh/ 原文:http://blog.csdn.net/sunboy_2050/article/details/7529841 前面两 ...
- git操作的各种命令整理
1.常用的Git命令 命令 简要说明 git add 添加至暂存区 git add–interactive 交互式添加 git apply 应用补丁 git am 应用邮件格式补丁 git ann ...
- git常用命令2
一. Git 常用命令速查 git branch 查看本地所有分支git status 查看当前状态 git commit 提交 git branch -a 查看所有的分支git branch -r ...
- Git 命令速查表
Git 命令速查表 1.常用的Git命令 命令 简要说明 git add 添加至暂存区 git add-interactive 交互式添加 git apply 应用补丁 git am 应用邮件格式补丁 ...
- Git 常用命令速查表(图文+表格)
一. Git 常用命令速查 git branch 查看本地所有分支git status 查看当前状态 git commit 提交 git branch -a 查看所有的分支git branch -r ...
- 转 Git 常用命令大全
一. Git 常用命令速查 git branch 查看本地所有分支 git status 查看当前状态 git commit 提交 git branch -a 查看所有的分支 git branch ...
随机推荐
- UVA103 dp基础题,DAG模型
1.UVA103 嵌套n维空间 DAG模型记忆化搜索,或者 最长上升子序列. 2.dp[i]=max( dp[j]+1),(第i个小于第j个) (1) //DAG模型记忆化搜索 #include< ...
- dotnetcore 单元测试
dotnetcore的单元测试目前支持的比较好的是xunit,首先通过nuget添加组件dotnet-test-xunit 和 xunit.如果有依赖注入可在构造方法中,相当于Nunit中的[Setu ...
- js库
lanchpad用的js库 http://lesscss.org/ https://github.com/EightMedia/hammer.js/wiki/Getting-Started http: ...
- Allegro之无法保存(提示和用户有关或者和lock有关)
使用中无意出现此情况 无奈重新打开文件时发现brd文件下面有个.brd.lck文件,顺手删掉,回复正常~ 此为bug解bug,具体方法下次遇到再仔细研究是为什么~ 养成隔几分钟手动保存的好习惯,防止b ...
- mysql如何在一个字段后面加个字符?
update city set 字段=concat(字段,'内容');
- JSP :运行最简单的 JSP 程序
160916 1. 代码和显示效果 <%@ page contentType="text/html; charset=GB2312" %> <%@ page im ...
- Java程序开发.邱加永2.1节
by2016.9.8 2.7.1 一维数组 1. 声明 int[] m: char[] c: double[] d: 2. 创建 数组声明之后还不能使用,m = new int[10]: c = ...
- web端限时活动逻辑处理总结
由于要在web端做一个限时活动的功能,功能大致为:一个小时内可以报名参加活动,然后给予报名者奖品,先到先得.用到一些处理逻辑做下总结,以前没有做过类似的东西,都是自己先体验其他网站的报名方式,然后再摸 ...
- 4.Powershell交互界面
Powershell提供两种接口:交互式和自动化脚本 先学下如何与Powershell Console和平共处,通过Powershell Console和机器学会对话. 通过以上一个简单测试,知道Po ...
- SQL Server复制出错文章集锦
SQL Server复制出错文章集锦 为了方便大家对数据库复制过程中出错的时候更好地解决问题 本人收集了SQL Server相关复制出错解决的文章 The process could not ex ...