一些操作实验的记录,哈哈哈
## 拉取远程仓库代码:可以认为就是一个下载命令,将服务器上面的代码下载到remote
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ git fetch
## 查看分支:可以看到目前只有三个分支,并且当前是处于test分支上面
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ git branch
dev
master
* test
## 切换分支: 从test切换分支到master上面
22477@yq MINGW64 /d/IDEA PROJECT/study_note (dev)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
22477@yq MINGW64 /d/IDEA PROJECT/study_note (master)
$ touch master.txt
22477@yq MINGW64 /d/IDEA PROJECT/study_note (master)
$ echo "master" >> master.txt
22477@yq MINGW64 /d/IDEA PROJECT/study_note (master)
$ cat master.txt
master
## 添加索引库
22477@yq MINGW64 /d/IDEA PROJECT/study_note (master)
$ git add .
warning: LF will be replaced by CRLF in master.txt.
The file will have its original line endings in your working directory
## 提交到本地仓库
22477@yq MINGW64 /d/IDEA PROJECT/study_note (master)
$ git commit -m "添加master文件"
[master da2faed] 添加master文件
1 file changed, 1 insertion(+)
create mode 100644 master.txt
22477@yq MINGW64 /d/IDEA PROJECT/study_note (master)
$ git checkout test
Switched to branch 'test'
Your branch is up to date with 'origin/test'.
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ ll
total 0
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ touch test.txt
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ echo "test" >> test.txt
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ cat test.txt
test
## 创建了test.txt,但是没有add到索引库,然后直接切换了分支
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
## 查看状态发现,text.txt文件显示是untracked状态,也会出现在master上面
22477@yq MINGW64 /d/IDEA PROJECT/study_note (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Untracked files:
(use "git add ..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
22477@yq MINGW64 /d/IDEA PROJECT/study_note (master)
$ git checkout test
Switched to branch 'test'
Your branch is up to date with 'origin/test'.
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ git status
On branch test
Your branch is up to date with 'origin/test'.
Untracked files:
(use "git add ..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ git add .
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ git commit -m "add test.txt"
[test 9ff6dab] add test.txt
1 file changed, 1 insertion(+)
create mode 100644 test.txt
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
## 推送到远程服务器: 将本地仓库推送到远程仓库
22477@yq MINGW64 /d/IDEA PROJECT/study_note (master)
$ git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Writing objects: 100% (3/3), 265 bytes | 265.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-5.0]
To https://gitee.com/Java0506/study_note.git
ab0a5e9..da2faed master -> master
22477@yq MINGW64 /d/IDEA PROJECT/study_note (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
22477@yq MINGW64 /d/IDEA PROJECT/study_note (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
22477@yq MINGW64 /d/IDEA PROJECT/study_note (master)
$ touch master2.txt
22477@yq MINGW64 /d/IDEA PROJECT/study_note (master)
$ echo "master2" >> master2.txt
22477@yq MINGW64 /d/IDEA PROJECT/study_note (master)
$ ll
total 2
-rw-r--r-- 1 22477 197610 8 4月 1 00:25 master.txt
-rw-r--r-- 1 22477 197610 8 4月 1 00:37 master2.txt
## 特别注意: 我在master上建立了master2.txt文件,并且git add到了索引库
22477@yq MINGW64 /d/IDEA PROJECT/study_note (master)
$ git add master2.txt
warning: LF will be replaced by CRLF in master2.txt.
The file will have its original line endings in your working directory
22477@yq MINGW64 /d/IDEA PROJECT/study_note (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged ..." to unstage)
new file: master2.txt
22477@yq MINGW64 /d/IDEA PROJECT/study_note (master)
$ git checkout test
Switched to branch 'test'
A master2.txt
Your branch is ahead of 'origin/test' by 1 commit.
(use "git push" to publish your local commits)
## 当我切换到test时,master2.txt也依然是等待提交,可以说明add其实是与分支无关的
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ git status
On branch test
Your branch is ahead of 'origin/test' by 1 commit.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git restore --staged ..." to unstage)
new file: master2.txt
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ git commit -m "错误提交了master2.txt到test"
[test 416b0ef] 错误提交了master2.txt到test
1 file changed, 1 insertion(+)
create mode 100644 master2.txt
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ ll
total 2
-rw-r--r-- 1 22477 197610 8 4月 1 00:37 master2.txt
-rw-r--r-- 1 22477 197610 6 4月 1 00:37 test.txt
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ git status
On branch test
Your branch is ahead of 'origin/test' by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
## 查看test的提交记录
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ git log test
commit 416b0efd6e7d93b3c7dfb3f12a6a5488fff719da (HEAD -> test)
Author: yancy.yi <[email protected]>
Date: Thu Apr 1 00:39:49 2021 +0800
错误提交了master2.txt到test
commit 9ff6dab5da4b017ca5e4f05abb445dad3ced2274
Author: yancy.yi <[email protected]>
Date: Thu Apr 1 00:25:16 2021 +0800
add test.txt
commit 11d809dcf52ca03705c670b99fcde353d3d9df93 (origin/test)
Author: yancy.yi <[email protected]>
Date: Thu Apr 1 00:17:00 2021 +0800
删除所有
commit 086a1708355e477bdb463904a649ecabb7537f61 (study_note/test)
Author: yancy.yi <[email protected]>
Date: Wed Mar 31 01:30:05 2021 +0800
撤销后再添加
commit 71314f32d1c8731b3bc6fe34ada88b47c99bf6d7
Author: yancy.yi <[email protected]>
Date: Wed Mar 31 01:28:20 2021 +0800
未推送到远程
commit 684c4b508a3411b96ef99f83bb38c394a6f12909
Merge: acb4b89 ade6ada
Author: yancy.yi <[email protected]>
## 执行git reset --hard HEAD^后会连同commitID一起删除,相当于没有提交过,只适用于commit,但没有push的情况
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ git reset --hard HEAD^
HEAD is now at 9ff6dab add test.txt
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ ll
total 1
-rw-r--r-- 1 22477 197610 6 4月 1 00:37 test.txt
22477@yq MINGW64 /d/IDEA PROJECT/study_note (test)
$ git log
commit 9ff6dab5da4b017ca5e4f05abb445dad3ced2274 (HEAD -> test)
Author: yancy.yi <[email protected]>
Date: Thu Apr 1 00:25:16 2021 +0800
add test.txt
commit 11d809dcf52ca03705c670b99fcde353d3d9df93 (origin/test)
Author: yancy.yi <[email protected]>
Date: Thu Apr 1 00:17:00 2021 +0800
删除所有
commit 086a1708355e477bdb463904a649ecabb7537f61 (study_note/test)
Author: yancy.yi <[email protected]>
Date: Wed Mar 31 01:30:05 2021 +0800
撤销后再添加
commit 71314f32d1c8731b3bc6fe34ada88b47c99bf6d7
Author: yancy.yi <[email protected]>
Date: Wed Mar 31 01:28:20 2021 +0800
未推送到远程