美文网首页
Git命令学习第三天

Git命令学习第三天

作者: Ican蓉 | 来源:发表于2020-04-10 16:26 被阅读0次

---------开始了

[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

相关文章

  • git 入门

    git 入门学习笔记----3个入门命令:git init、git add、git commit -v 学习场景(...

  • Git命令学习第三天

    ---------开始了 [root@MiWiFi-R3A-srv git-practice]# ls add.t...

  • 2.1 分支branch 基本管理操作

    主要学习命令:git branch、git checkout [root@localhost git]# mkdi...

  • git常用命令

    (转载)学习 git 常用命令 基本命令 查看命令 合并分支 远程分支 Git主分支的名字,默认叫做Master。...

  • git 使用

    ---恢复内容开始--- 1.学习 git 命令 $ git help //查看帮助 $ git help ini...

  • Git学习----版本回退(reset & revert)

    前提 git已提交几次代码。具体方式见:Git命令学习----常用命令[https://www.jianshu.c...

  • Git 命令

    Git学习 Git命令 git init 初始化文件 git status 查看状态 git rm 删除未添加到索...

  • Github学习文档-3

    目录 1.Git 的基本的命令git init命令git status命令git add命令git commit命...

  • 软件测试攻略(十八):Linux命令¬epad++拓展&页

    一、Linux命令 百度先行下载Git,使用Git Bush模拟Lunix环境学习Linux命令。 二、notep...

  • Git 命令学习

    最近在看 廖雪峰的 Git 教程 真心推荐,作为开发都去看下,大概零零散散用了一天时间吧,把整个教程看了一遍,跟这...

网友评论

      本文标题:Git命令学习第三天

      本文链接:https://www.haomeiwen.com/subject/ttlrmhtx.html