git init
git init [project-name]
git clone [url]
git config --lits
git config -e --gloal
git config --global user.email "youremail@example.com"
git config --global user.name "yourName"
所有的的版本控制系统只能追踪文本文件的改动,比如TXT文件,网页,所有的程序代码等等。版本控制系统可以告诉你每次的改动,比如在第五行加了一个单词"Linux",在第八行删除了"Windows"等等。而图片,视频这些二进制文件,虽然也能由版本控制系统管理,但没法跟踪文件的变化,只能把二进制文件每次改动串起来,也就只知道图片从100k改成了120k。
其中Microsoft的Word格式是二进制格式,因此控制版本系统无法跟踪Word文档的改动。
git add [file1] [file2]
git add [dir]
git add .
git add -p
git rm [file1] [file2]
git mv [file-original] [file-renamed]
git checkout -- [file]
git reset HEAD [file]
git diff HEAD -- [file]
$ git diff HEAD -- README.txt
diff --git a/README.txt b/README.txt
index ab76794..0f8a8e9 100644
--- a/README.txt
+++ b/README.txt
@@ -1,3 +1,4 @@
this is an test
test enter
test again
+test diff
git commit -m "message"
git commit [file1] [file2] -m "message"
git commit -a
git commit -v
git commit --amend -m "message"
git commit --amend [file1] [file2]
git log
如下:
commit 03d99a41e6df6d5c9f178469d2486d3f18b31676
Author: rasang <test@qq.com>
Date: Sun Aug 25 17:52:59 2019 +0800
test3
commit b099664a069db05bbde874fc5bae325183885104
Author: rasang <test@qq.com>
Date: Sun Aug 25 17:50:10 2019 +0800
test2
commit 01197a271ada3f03b80493446a6353e410f9a621
Author: rasang <test@qq.com>
Date: Sun Aug 25 17:48:23 2019 +0800
test1
commit后面跟着的就是commit-id,使用如下命令回退版本
git reset --hard [commit-id]
也可以使用如下命令返回上一个版本
git reset HEAD^
而HEAD^^
则是上上个版本,回退前100个版本的指令为
git reset HEAD~100
回退版本后,晚于该版本的log会消失,想要回到原来的版本,需要使用git reflog
查看穿梭的记录
$ git reflog
03d99a4 (HEAD -> master) HEAD@{0}: reset: moving to HEAD^
4e75dd6 HEAD@{1}: commit: upper
03d99a4 (HEAD -> master) HEAD@{2}: reset: moving to 03d99a41e6df6
df136f4 HEAD@{3}: reset: moving to df136f
df136f4 HEAD@{4}: reset: moving to df136f499b87ac6d6b2
df136f4 HEAD@{5}: commit: delete
113dcfe HEAD@{6}: commit: test4
03d99a4 (HEAD -> master) HEAD@{7}: commit: test3
b099664 HEAD@{8}: commit: test2
01197a2 HEAD@{9}: commit (initial): test1
如果之前没有创建过,可输入:
ssh-keygen -t rsa -C "youremail@example.com"
一路回车,可在用户主目录下生成.ssh目录,其中id_rsa为私钥,id_rsa.pub是公钥。然后就可以进入代码托管平台将公钥里的内容添加到账号的公钥里面了
在代码托管平台上新建一个仓库,可以从这个仓库克隆出新的仓库,也可以把一个已有的本地仓库与之关联,然后,把本地仓库的内容推送到GitHub仓库。
关联远程仓库:
git remote add origin [git_add]
关联后使用git push -u origin master
第一次推送master分支所有内容,此后则用git push origin master
推送最新更新
首先要知道仓库地址,一般都是在代码页就有了,然后使用指令git clone [git_add]
就好了
git branch -p [brach_name]
git branch
当前分支前面会标一个*号
git checkout [branch_name]
git merge dev
将dev分支合并到当前分支
git branch -d dev
git log --graph
原文:https://www.cnblogs.com/Rasang/p/11409094.html