---------开始了
[root@MiWiFi-R3A-srv git-practice]# ls
add.txt mygit-practice StudyGit
#添加指定文件到暂存区
[root@MiWiFi-R3A-srv git-practice]# git add add.txt
#添加指定目录到暂存区,包括子目录
[root@MiWiFi-R3A-srv git-practice]# git add StudyGit
[root@MiWiFi-R3A-srv git-practice]# cd StudyGit
[root@MiWiFi-R3A-srv StudyGit]# ls
LICENSE README.md
#添加当前目录的所有文件到暂存区
[root@MiWiFi-R3A-srv StudyGit]# git add .
#查看仓库状态,看是否成功
[root@MiWiFi-R3A-srv StudyGit]# git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
#遇到问题1:我百度了一下,是版本分支的问题
#新建一个版本分支
[root@MiWiFi-R3A-srv StudyGit]# git branch rongbranch
#查看分支是否创建成功,(前面的*代表的是当前你所在的工作分支)
[root@MiWiFi-R3A-srv StudyGit]# git branch
* master
rongbranch
#切换到你的新分支
[root@MiWiFi-R3A-srv StudyGit]# git checkout rongbranch
Switched to branch 'rongbranch'
[root@MiWiFi-R3A-srv StudyGit]# ls
LICENSE README.md
[root@MiWiFi-R3A-srv StudyGit]# git add .
[root@MiWiFi-R3A-srv StudyGit]# git status
On branch rongbranch
nothing to commit, working tree clean
#遇到问题2:百度意思是不能提交且工作数里面也是空的,可能是我之前提交过了
#新建一个新目录,新目录下有目录和文件,再试一遍,就成功了
[root@MiWiFi-R3A-srv StudyGit]# mkdir ss
[root@MiWiFi-R3A-srv StudyGit]# cd ss
[root@MiWiFi-R3A-srv ss]# touch qq.txt
[root@MiWiFi-R3A-srv ss]# mkdir ww
[root@MiWiFi-R3A-srv ss]# ls
qq.txt ww
[root@MiWiFi-R3A-srv ss]# git add .
[root@MiWiFi-R3A-srv ss]# git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: ../README.md
new file: qq.txt
new file: ../ss1.txt
[root@MiWiFi-R3A-srv ss]# ls
qq.txt ww
#将文件移除缓存区
[root@MiWiFi-R3A-srv ss]# git rm --cached qq.txt
rm 'ss/qq.txt'
[root@MiWiFi-R3A-srv ss]# git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: ../README.md
new file: ../ss1.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
./
[root@MiWiFi-R3A-srv ss]# cd ..
#切换到主分支
[root@MiWiFi-R3A-srv StudyGit]# git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
#然后将新分支提交的改动合并到主分支上
[root@MiWiFi-R3A-srv StudyGit]# git merge rongbranch
Already up-to-date.
#删除工作区文件,并且将这次删除放入暂存区
[root@MiWiFi-R3A-srv StudyGit]# git rm README.md
rm 'README.md'
[root@MiWiFi-R3A-srv StudyGit]# touch ss.txt
[root@MiWiFi-R3A-srv StudyGit]# git rm ss.txt ...
fatal: pathspec 'ss.txt' did not match any files
[root@MiWiFi-R3A-srv StudyGit]# ls
LICENSE ss.txt
#改名文件,并且将这个改名放入暂存区
[root@MiWiFi-R3A-srv StudyGit]# git mv ss.txt ss1.txt
fatal: not under version control, source=ss.txt, destination=ss1.txt
#遇到问题3:有道翻译(无路径的文件:(使用“git添加<文件>…”来包含将要提交的内容)
[root@MiWiFi-R3A-srv StudyGit]# ll
total 20
-rw-r--r--. 1 root root 18038 Apr 8 01:13 LICENSE
-rw-r--r--. 1 root root 0 Apr 10 15:40 ss.txt
[root@MiWiFi-R3A-srv StudyGit]# git mv ss.txt ss1.txt
fatal: not under version control, source=ss.txt, destination=ss1.txt
#查看仓库状态,知道了原因
[root@MiWiFi-R3A-srv StudyGit]# git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: README.md
Untracked files:
(use "git add <file>..." to include in what will be committed)
ss.txt
#该文件不存在了,需要再次添加
[root@MiWiFi-R3A-srv StudyGit]# git add ss.txt
#再次进行重命名文件,OK,成功了!
[root@MiWiFi-R3A-srv StudyGit]# git mv ss.txt ss1.txt
[root@MiWiFi-R3A-srv StudyGit]# ls
LICENSE ss1.txt
[root@MiWiFi-R3A-srv StudyGit]#
汇总问题如下:
#遇到问题1:On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
原因:我百度了一下,是版本分支的问题
#遇到问题2:nothing to commit, working tree clean
原因:百度意思是不能提交且工作数里面也是空的,可能是我之前提交过了
解决办法参考:https://jingyan.baidu.com/article/49ad8bce2cb8eb1835d8fa4e.html
#遇到问题3:fatal: not under version control, source=ss.txt, destination=ss1.txt
原因:有道翻译(无路径的文件:(使用“git添加<文件>…”来包含将要提交的内容)
解决办法参考:https://blog.csdn.net/zhongxu_yuan/article/details/100000386
网友评论