标签:and 自己 最新版 error alt 命令 == 名称 oba
目录
git config --global user.name "Your Name"
git config --global user.email "email@example.com"
git config user.name
git config user.email
git config --list
ssh-keygen -t rsa -C"example@qq.com"
,连按三次回车,即可生成ssh-key;ssh -T git@github.com
cd ~/.ssh
ls -a
电脑上已经安装了git;
在新的空的目录下创建一个文件夹practiceGit
,在这个目录下创建文件promoteGit.txt
,通过对该文件的操作来进行基本命令的学习!
#git文件夹下创建practiceGit目录
localhost:git mac$ mkdir practiceGit
#切换到practiceGit目录下
localhost:git mac$ cd practiceGit
#添加一个文件promoteGit.txt
localhost:practiceGit mac$ touch promoteGit.txt
创建git仓库
主要命令git init
、git add
、git commit
。
#初始化仓库
localhost:practiceGit mac$ git init
Initialized empty Git repository in /Users/...
#查看这个目录 会看到初始化仓库后有 .git文件
localhost:practiceGit mac$ ls -la
#编辑这个文件
localhost:practiceGit mac$ vim promoteGit.txt
#填写以下单词,保存并退出。
today!
start practice git!
#把文件添加到仓库
localhost:practiceGit mac$ git add promoteGit.txt
#把文件提交到仓库 -m后面输入的是本次提交的说明。
localhost:practiceGit mac$ git commit -m "start git learn"
[master (root-commit) 960dad7] start git learn
1 file changed, 2 insertions(+)
create mode 100644 promoteGit.txt
学习git status
、git diff
命令。
#修改该文件
localhost:practiceGit mac$ vim promoteGit.txt
#添加一行单词ONE!
today!
start practice git!
ONE!
#使用 git status命令,查看结果,它提示已经修改但是还没提交
localhost:practiceGit mac$ 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: promoteGit.txt
no changes added to commit (use "git add" and/or "git commit -a")
#使用 git diff 查看修改的内容
localhost:practiceGit mac$ git diff promoteGit.txt
diff --git a/promoteGit.txt b/promoteGit.txt
index 8db65ab..2144d7b 100644
--- a/promoteGit.txt
+++ b/promoteGit.txt
@@ -1,2 +1,3 @@
today!
start practice git!
+ONE!
#之后便可以进行add和commit操作
localhost:practiceGit mac$ git add promoteGit.txt
#查看状态
localhost:practiceGit mac$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: promoteGit.txt
#提交
localhost:practiceGit mac$ git commit -m "add ONE"
[master 5869fb0] add ONE
1 file changed, 1 insertion(+)
#查看状态
localhost:practiceGit mac$ git status
On branch master
nothing to commit, working tree clean
学习git log
、git reset
、git reflog
等命令
#编辑promoteGit.txt文件,添加TWO单词
localhost:practiceGit mac$ vim promoteGit.txt
today!
start practice git!
ONE TWO!
#添加至仓库并提交
localhost:practiceGit mac$ git add promoteGit.txt
#提交
localhost:practiceGit mac$ git commit -m "add TWO"
[master dea363c] add TWO
1 file changed, 1 insertion(+), 1 deletion(-)
#查看提交历史 git log
localhost:practiceGit mac$ git log
commit dea363cb40cacc3b0d6efb7dc8855e9c977fbf31 (HEAD -> master)
Author: *****
Date: Wed Jan 8 23:11:31 2020 +0800
add TWO
commit 5869fb088f10361fb3b1a028285d39d29a1f20ce
Author: *****
Date: Wed Jan 8 23:04:32 2020 +0800
add ONE
commit 960dad7ae9fde8d903b9c2e311c2aa63a4974472
Author: *****
Date: Wed Jan 8 22:49:45 2020 +0800
start git learn
#查看提交历史 简洁版的 git log --pretty=oneline
localhost:practiceGit mac$ git log --pretty=oneline
dea363cb40cacc3b0d6efb7dc8855e9c977fbf31 (HEAD -> master) add TWO
5869fb088f10361fb3b1a028285d39d29a1f20ce add ONE
960dad7ae9fde8d903b9c2e311c2aa63a4974472 start git learn
#版本回退到 “ONE”的版本 上一个版本:HEAD^ 上上一个版本:HEAD^^ 上10个版本:HEAD~10
localhost:practiceGit mac$ git reset --hard HEAD^
HEAD is now at 5869fb0 add ONE
#查看文件
localhost:practiceGit mac$ cat promoteGit.txt
today!
start practice git!
ONE!
#查看提交历史
localhost:practiceGit mac$ git log
commit 5869fb088f10361fb3b1a028285d39d29a1f20ce (HEAD -> master)
Author: *****
Date: Wed Jan 8 23:04:32 2020 +0800
add ONE
commit 960dad7ae9fde8d903b9c2e311c2aa63a4974472
Author: *****
Date: Wed Jan 8 22:49:45 2020 +0800
start git learn
#回到最新版本
localhost:practiceGit mac$ git reset --hard dea36
HEAD is now at dea363c add TWO
localhost:practiceGit mac$ cat promoteGit.txt
today!
start practice git!
ONE TWO!
#git reflog 记录每一次命令
localhost:practiceGit mac$ git reflog
dea363c (HEAD -> master) HEAD@{0}: reset: moving to dea36
5869fb0 HEAD@{1}: reset: moving to HEAD^
dea363c (HEAD -> master) HEAD@{2}: commit: add TWO
5869fb0 HEAD@{3}: commit: add ONE
960dad7 HEAD@{4}: commit (initial): start git learn
工作区和暂存区概念
学习 git checkout -- file
、git reset HEAD file
git checkout -- file
撤销工作区修改。#修改promoteGit.txt文件,添加 delect me. 这一行,未提交至暂存区,在工作区的修改全部撤销!
localhost:practiceGit mac$ cat promoteGit.txt
today!
start practice git!
ONE TWO!
delect me.
#查看工作区状态
localhost:practiceGit mac$ 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: promoteGit.txt
no changes added to commit (use "git add" and/or "git commit -a")
#在工作区的修改全部撤销
localhost:practiceGit mac$ git checkout -- promoteGit.txt
#查看结果
localhost:practiceGit mac$ cat promoteGit.txt
today!
start practice git!
ONE TWO!
git reset HEAD file
、在撤销git checkout -- file
。#添加至暂存区
localhost:practiceGit mac$ git add promoteGit.txt
#查看变化
localhost:practiceGit mac$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: promoteGit.txt
#使用最新的版本 git reset HEAD 把暂存区的修改撤销掉(unstage),重新放回工作区。
localhost:practiceGit mac$ git reset HEAD promoteGit.txt
Unstaged changes after reset:
M promoteGit.txt
#查看状态
localhost:practiceGit mac$ 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: promoteGit.txt
no changes added to commit (use "git add" and/or "git commit -a")
#撤销工作区修改
localhost:practiceGit mac$ git checkout -- promoteGit.txt
localhost:practiceGit mac$ cat promoteGit.txt
today!
start practice git!
ONE TWO!
学习删除文件命令git rm <file>
删除版本库中的文件。
#背景:添加deleteFile.txt,测试删除该文件
localhost:practiceGit mac$ git add deleteFile.txt
#查看仓库状态
localhost:practiceGit mac$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: deleteFile.txt
#提交到版本库
localhost:practiceGit mac$ git commit -m "测试文件删除"
[master d79d315] 测试文件删除
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 deleteFile.txt
#查看记录每一次命令
localhost:practiceGit mac$ git reflog
d79d315 (HEAD -> master) HEAD@{0}: commit: 测试文件删除
dea363c HEAD@{1}: reset: moving to dea36
5869fb0 HEAD@{2}: reset: moving to HEAD^
dea363c HEAD@{3}: commit: add TWO
5869fb0 HEAD@{4}: commit: add ONE
960dad7 HEAD@{5}: commit (initial): start git learn
#在工作区删除该文件
localhost:practiceGit mac$ rm deleteFile.txt
#查看仓库状态
localhost:practiceGit mac$ git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: deleteFile.txt
no changes added to commit (use "git add" and/or "git commit -a")
#第一种情况:工作区删除文件,恢复删除的文件
localhost:practiceGit mac$ git checkout -- deleteFile.txt
localhost:practiceGit mac$ ls -la
total 8
drwxr-xr-x 5 mac staff 160 1 13 17:42 .
drwxr-xr-x 4 mac staff 128 1 9 23:20 ..
drwxr-xr-x 13 mac staff 416 1 13 17:42 .git
-rw-r--r-- 1 mac staff 0 1 13 17:42 deleteFile.txt
-rw-r--r-- 1 mac staff 36 1 13 17:20 promoteGit.txt
#第二种情况:将版本库中的文件删除并提交
localhost:practiceGit mac$ git rm deleteFile.txt
rm 'deleteFile.txt'
#提交
localhost:practiceGit mac$ git commit -m "版本库中文件删除"
[master b21ea4a] 版本库中文件删除
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 deleteFile.txt
#查看每一次的提交
localhost:practiceGit mac$ git reflog
b21ea4a (HEAD -> master) HEAD@{0}: commit: 版本库中文件删除
d79d315 HEAD@{1}: commit: 测试文件删除
dea363c HEAD@{2}: reset: moving to dea36
5869fb0 HEAD@{3}: reset: moving to HEAD^
dea363c HEAD@{4}: commit: add TWO
5869fb0 HEAD@{5}: commit: add ONE
960dad7 HEAD@{6}: commit (initial): start git learn
先在码云上创建一个仓库,写上仓库名称、归属、基本介绍等信息;
创建好仓库后,在自己存在的项目下,依次使用以下命令:
#本地初始化项目
$ git init
#将本地仓库和远程仓库相关联
$ git remote add origin <克隆或者复制的仓库名称>
#拉取远程仓库
$ git pull origin master
初始化、设置远程仓库地址后再做push、pull命令拉取诸如 .gitignore 文件等;
在.gitignore文件中编写需要忽略的文件,例如 .idea、.gradle等。
就可以提交新的更改的代码分支了。
准备工作:先在该仓库下创建originPractise.txt文件,并在文件下添加一行文字!
$ touch originPractise.txt
$ vim originPractise.txt
$ cat originPractise.txt
练习远程命令!
创建分支、合并分支、删除分支等命令
git checkout -b dev
加上-b
创建并切换分支,相当于git branch dev
、git checkout dev
命令;git branch
,查看当前分支;git checkout master
切换至master分支;git merge dev
,合并指定分支到当前分支;git branch -d dev
,合并后删除该分支;git switch -c dev
,创建+切换分支;git switch master
,切换至master分支;#创建dev分支并切换
$ git checkout -b dev
Switched to a new branch 'dev'
#查看当前分支
$ git branch
* dev
master
#在dev分支上修改该文件
$ vim originPractise.txt
$ cat originPractise.txt
练习远程命令!
创建dev分支!
#添加仓库并提交
$ git add originPractise.txt
$ git commit -m "在dev分支上进行修改!"
[dev cedbf27] 在dev分支上进行修改!
1 file changed, 1 insertion(+)
#切换至master分支
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
#查看该分支上该文件,发现dev分支上的修改在master分支上并没有修改
$ cat originPractise.txt
练习远程命令!
#合并dev分支到当前分支(master)
$ git merge dev
Updating 85c20fd..cedbf27
Fast-forward
originPractise.txt | 1 +
1 file changed, 1 insertion(+)
#查看该分支,发现dev上的修改已经合并至master上
$ cat originPractise.txt
练习远程命令!
创建dev分支!
#删除dev分支
$ git branch -d dev
Deleted branch dev (was cedbf27).
#查看分支
$ git branch
* master
合并冲突!命令git log --graph --pretty=oneline --abbrev-commit
查看分支合并图。
#新创建figure分支并切换到该分支
$ git checkout -b figure
Switched to a new branch 'figure'
#查看分支
$ git branch
* figure
master
#在该分支编辑该文件
$ vim originPractise.txt
$ cat originPractise.txt
练习远程命令!
创建dev分支!
最新创建一个figure分支,
用来测试一下冲突!
#添加到仓库并提交
$ git add originPractise.txt
$ git commit -m "figure分支修改文件,测试冲突!"
[figure b2d73d8] figure分支修改文件,测试冲突!
1 file changed, 2 insertions(+), 1 deletion(-)
#切换至master分支
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
#查看分支
$ git branch
figure
* master
#在master分支编辑该文件并提交
$ vim originPractise.txt
$ git add originPractise.txt
$ git commit -m "master分支上修改同一份文件!"
[master 8770136] master分支上修改同一份文件!
1 file changed, 3 insertions(+), 1 deletion(-)
#将figure分支上文件合并至master
$ git merge figure
Auto-merging originPractise.txt
CONFLICT (content): Merge conflict in originPractise.txt
Automatic merge failed; fix conflicts and then commit the result.
#查看状态
$ git status
On branch master
Your branch is ahead of 'origin/master' by 3 commits.
(use "git push" to publish your local commits)
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: originPractise.txt
no changes added to commit (use "git add" and/or "git commit -a")
#查看冲突文件,可以看到“<<<<<<<” "=======" ">>>>>>>"
$ cat originPractise.txt
练习远程命令!
创建dev分支!
<<<<<<< HEAD
新创建一个figure分支;
使用master分支;
测试一下冲突!
=======
最新创建一个figure分支,
用来测试一下冲突!
>>>>>>> figure
#解决冲突并提交
$ vim originPractise.txt
$ git add originPractise.txt
$ git commit -m "冲突合并完成了!"
[master 4bb257a] 冲突合并完成了!
#查看合并冲突时的曲线图
$ git log --graph --pretty=oneline --abbrev-commit
* 4bb257a (HEAD -> master) 冲突合并完成了!
|\
| * b2d73d8 (figure) figure分支修改文件,测试冲突!
* | 8770136 master分支上修改同一份文件!
|/
* 90d88e3 figure分支修改!
* cedbf27 在dev分支上进行修改!
* 85c20fd (origin/master) 修改一版文件
#删除该分支
$ git branch -d figure
Deleted branch figure (was b2d73d8).
不使用快速合并(Fast forward),git merge --no-ff -m "提交时的描述" dev
,该命令合并dev至master时,禁止使用Fast forward方式合并,这次合并时要创建一个新的commit,故其中有-m参数。
命令git stash
、git stash list
、git stash pop
、git stash apply
、git stash drop
、git cherry-pick <commit>
等命令。
$ git checkout -b dev
Switched to a new branch 'dev'
$ git branch
* dev
master
$ vim originPractise.txt
#查看状态,工作区中有未提交的文件
$ git status
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: originPractise.txt
no changes added to commit (use "git add" and/or "git commit -a")
#在dev分支中,将工作区修改的文件贮藏。
$ git stash
Saved working directory and index state WIP on dev: 4bb257a 冲突合并完成了!
#贮藏后可以看到工作区干净
$ git status
On branch dev
nothing to commit, working tree clean
#切换至maste
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 5 commits.
(use "git push" to publish your local commits)
#新拉分支改bug
$ git checkout -b temp1
Switched to a new branch 'temp1'
#第五行添加 “figure分支和master分支”
$ vim originPractise.txt
$ cat originPractise.txt
练习远程命令!
创建dev分支!
新创建一个figure分支;
使用master分支;
figure分支和master分支测试一下冲突!
最新创建一个figure分支,
用来测试一下冲突!
#添加并提交
$ git add originPractise.txt
$ git commit -m "五行修改"
[temp1 29ecde1] 五行修改
1 file changed, 1 insertion(+), 1 deletion(-)
$ git status
On branch temp1
nothing to commit, working tree clean
$ git log --pretty=oneline
29ecde1a07943e71bafa4dc23d3fe60f37f2db14 (HEAD -> temp1) 五行修改
4bb257afa90d3d0b68ca18a065a9506f14a861fc (master, dev) 冲突合并完成了!
.....
#切换分支
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 5 commits.
(use "git push" to publish your local commits)
$ cat originPractise.txt
练习远程命令!
创建dev分支!
新创建一个figure分支;
使用master分支;
测试一下冲突!
最新创建一个figure分支,
用来测试一下冲突!
#将修改bug的temp1分支上合并至maste分支。
$ git merge --no-ff -m "temp1合并至master" temp1
Merge made by the 'recursive' strategy.
originPractise.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
#查看提交历史
$ git log --pretty=oneline
82f684466603a75a969ea18246953bb2400e8c34 (HEAD -> master) temp1合并至master
29ecde1a07943e71bafa4dc23d3fe60f37f2db14 (temp1) 五行修改
4bb257afa90d3d0b68ca18a065a9506f14a861fc (dev) 冲突合并完成了!
....
#切换至dev
$ git checkout dev
Switched to branch 'dev'
$ git status
On branch dev
nothing to commit, working tree clean
#查看暂存的文件列表
$ git stash list
stash@{0}: WIP on dev: 4bb257a 冲突合并完成了!
#应用贮藏的文件并删除
$ 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: originPractise.txt
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (c412328d523e22db6d04107c0968ad816ec2da56)
#查看暂存的文件列表 可以看到应用后贮藏的文件消失
$ git stash list
#查看dev中修改的文件
$ cat originPractise.txt
练习远程命令!
创建dev分支!
新创建一个figure分支;
使用master分支;
测试一下冲突!
最新创建一个figure分支,
用来测试一下冲突!
哈哈哈哈哈哈!
测试暂存功能!
#添加并提交
$ git add originPractise.txt
$ git commit -m "应用贮藏后dev分支修改后提交"
[dev 2901f6a] 应用贮藏后dev分支修改后提交
1 file changed, 2 insertions(+), 1 deletion(-)
#查看合并曲线图
$ git log --graph --pretty=oneline --abbrev-commit
* 2901f6a (HEAD -> dev) 应用贮藏后dev分支修改后提交
* 4bb257a 冲突合并完成了!
|\
| * b2d73d8 figure分支修改文件,测试冲突!
* | 8770136 master分支上修改同一份文件!
|/
* 90d88e3 figure分支修改!
...
#将temp1分支上的修改提交合并到dev上,因为这个修改是在master上修改的,dev中并不是最新的修改。
$ git cherry-pick 29ecde
[dev 7e10494] 五行修改
Date: Wed Jan 15 14:35:04 2020 +0800
1 file changed, 1 insertion(+), 1 deletion(-)
#可以看到已经合并完成
$ cat originPractise.txt
练习远程命令!
创建dev分支!
新创建一个figure分支;
使用master分支;
figure分支和master分支测试一下冲突!
最新创建一个figure分支,
用来测试一下冲突!
哈哈哈哈哈哈!
测试暂存功能!
命令git branch -D name
删除未进行合并操作的分支
#新建分支temp2
$ git checkout -b temp2
Switched to a new branch 'temp2'
$ vim originPractise.txt
#添加并提交
$ git add originPractise.txt
$ git commit -m "temp2分支添加最后一行"
[temp2 fabd6f8] temp2分支添加最后一行
1 file changed, 1 insertion(+)
#删除该分支 在当前分支时不能删除本分支
$ git branch -d temp2
error: Cannot delete branch 'temp2' checked out at '/***/**'
#切换分支至dev
$ git checkout dev
Switched to branch 'dev'
#删除temp2分支报错
$ git branch -d temp2
error: The branch 'temp2' is not fully merged.
If you are sure you want to delete it, run 'git branch -D temp2'.
#使用-D参数删除
$ git branch -D temp2
Deleted branch temp2 (was fabd6f8).
多人共同开发
#查看远程库信息
$ git remote
origin
#更详细的远程库信息
$ git remote -v
origin https://gitee.com/***/***.git (fetch)
origin https://gitee.com/***/***.git (push)
#推送信息到远程仓库
$ git push origin master
Counting objects: 26, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (25/25), done.
Writing objects: 100% (26/26), 2.53 KiB | 862.00 KiB/s, done.
Total 26 (delta 16), reused 0 (delta 0)
remote: Checking connectivity: 26, done.
remote: Powered by GITEE.COM [GNK-3.8]
To https://gitee.com/***/***.git
85c20fd..c32a72d master -> master
#从远程拉取信息
$ git pull
Already up to date.
#把本地未push的分叉提交历史整理成直线之后在push
$ git rebase
学习git tag tagname
、git tag
、git show tagname
、git tag -a tagname -m "标签的说明"
等命令。
#查看当前分支
$ git branch
dev
* master
temp1
#在该分支上打上标签
$ git tag Version_001
#查看所有标签
$ git tag
Version_001
#查看提交历史
$ git log --pretty=oneline --abbrev-commit
c32a72d (HEAD -> master, tag: Version_001, origin/master) dev合并至master
7e10494 (dev) 五行修改
2901f6a 应用贮藏后dev分支修改后提交
82f6844 temp1合并至master
29ecde1 (temp1) 五行修改
......
#在指定的commit上打上标签
$ git tag Version_002 2901f6a
#查看所有标签
$ git tag
Version_001
Version_002
#查看标签信息
$ git show Version_002
commit 2901f6a13aa1a66eb122543cc9d052c151cbb2b0 (tag: Version_002)
Author: ***
Date: ***
应用贮藏后dev分支修改后提交
diff --git a/originPractise.txt b/originPractise.txt
index bae6658..8290d74 100644
--- a/originPractise.txt
+++ b/originPractise.txt
@@ -5,4 +5,5 @@
测试一下冲突!
#在指定的commit上打上标签 并添加标签的说明
$ git tag -a Version_003 -m "用来测试填写有说明文字的标签" 7e10494
$ git show Version_003
tag Version_003
Tagger: ***
Date: ***
用来测试填写有说明文字的标签
commit 7e104945ce32611ab687477d23885e948afeadb0 (tag: Version_003, dev)
Author: ***
Date: ***
五行修改
学习git push origin tagname
、git push origin --tags
、git tag -d tagname
、git push origin :refs/tags/tagname
等命令。
#查看所有标签
$ git tag
Version_001
Version_002
Version_003
#推送标签到远程
$ git push origin Version_001
Total 0 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-3.8]
To https://gitee.com/***/***.git
* [new tag] Version_001 -> Version_001
#删除本地标签
$ git tag -d Version_003
Deleted tag 'Version_003' (was 9c95d1a)
#查看所有标签
$ git tag
Version_001
Version_002
#将所有标签推送到远程 推送后可以通过码云看是否推送成功
$ git push origin --tags
Total 0 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-3.8]
To https://gitee.com/***/***.git
* [new tag] Version_002 -> Version_002
#删除已推送到远程的标签 先删除本地的标签
$ git tag -d Version_002
Deleted tag 'Version_002' (was 2901f6a)
#再删除远程的标签 删除后可上码云上看是否删除成功
$ git push origin :refs/tags/Version_002
remote: Powered by GITEE.COM [GNK-3.8]
To https://gitee.com/***/***.git
- [deleted] Version_002
#初始化仓库
$ git init
#将文件添加到仓库
$ git add <file>
#提交到仓库
$ git commit -m <message>
#时刻掌握仓库当前的状态
$ git status
#查看文件的不同 查看difference
$ git diff <file>
#查看提交历史 简洁版的 git log --pretty=oneline
$ git log (--pretty=oneline)
#版本回退
$ git reset --hard <commit_id>
#记录每一次命令 历史命令
$ git reflog
#丢弃工作区的修改
$ git checkout -- <file>
#丢弃暂存区上的修改,将它放回到工作区
$ git reset HEAD <file>
#删除文件
$ git rm <file>
#关联远程库
$ git remote add origin git@server-name:path/repo-name.git
#创建dev分支并切换
$ git checkout -b dev
#查看当前分支
$ git branch
#切换至master分支
$ git checkout master
#合并dev分支到当前分支(master)
$ git merge dev
#删除dev分支
$ git branch -d dev
#禁止使用Fast forward方式合并
$ git merge --no-ff -m "提交时的描述" dev
#将工作区修改的文件贮藏
$ git stash
#查看暂存的文件列表
$ git stash list
#应用贮藏的文件并删除
$ git stash pop
#恢复贮藏的文件后不删除
$ git stash apply
#删除贮藏的文件
$ git stash drop
#将已经提交的分支合并至当前分支。
$ git cherry-pick <commit>
#删除未进行合并操作的分支
$ git branch -D name
#查看远程库信息
$ git remote
#更详细的远程库信息
$ git remote -v
#推送信息到远程仓库
$ git push origin master
#从远程拉取信息
$ git pull
#创建本地分支和远程分支的链接
$ git branch --set-upstream-to <branch-name> origin/<branch-name>
#把本地未push的分叉提交历史整理成直线之后在push
$ git rebase
#在默认分支上打上标签 默认是HEAD
$ git tag tagname (commit id)
#查看所有标签
$ git tag
#查看标签信息
$ git show tagname
#在指定的commit上打上标签 并添加标签的说明
$ git tag -a tagname -m "标签的说明文字" 7e10494
#推送标签到远程
$ git push origin tagname
#将所有标签推送到远程 推送后可以通过码云看是否推送成功
$ git push origin --tags
#删除本地标签
$ git tag -d tagname
#再删除远程的标签 删除后可上码云上看是否删除成功
$ git push origin :refs/tags/tagname
#版本回退
$ git reset --hard <commit_id>
#丢弃暂存区上的修改,将它放回到工作区 HEAD
$ git reset HEAD <file>
#创建并切换分支
$ git checkout -b <name>
$ git switch -c <name>
#切换分支
$ git checkout <name>
$ git switch <name>
本次博文参考廖雪峰大佬的Git教程,附上链接:https://www.liaoxuefeng.com/wiki/896043488029600 !
原创不易,欢迎转载,转载时请注明出处,谢谢!
作者:潇~萧下
原文链接:https://www.cnblogs.com/manongxiao/p/12202243.html
标签:and 自己 最新版 error alt 命令 == 名称 oba
原文地址:https://www.cnblogs.com/manongxiao/p/12202243.html