查看仓库的状态

  1. $ git status
  2. On branch master
  3. No commits yet
  4. Untracked files: # 未被追踪的问题
  5. (use "git add <file>..." to include in what will be committed)
  6. hello.txt
  7. nothing added to commit but untracked files present (use "git add" to track)

添加文件到暂存区

git add [文件名]

  1. $ git add hello.txt
  2. warning: LF will be replaced by CRLF in hello.txt. # git将CRLF替换成LF,windows里面换行符是CRLF,linux里面换行符是LF
  3. The file will have its original line endings in your working directory

查看文件状态

  1. root@ZJJ MINGW64 /f/projectDemo (master)
  2. $ git status
  3. On branch master
  4. No commits yet
  5. Changes to be committed:
  6. (use "git rm --cached <file>..." to unstage)
  7. new file: hello.txt # 文件被git追踪到了,这个文件只是在暂存区里面,此时还没将这个文件保存到历史版本
  8. root@ZJJ MINGW64 /f/projectDemo (master)

将文件从暂存区里面删除掉

git rm —cached [文件名]

  1. root@ZJJ MINGW64 /f/projectDemo (master)
  2. $ git rm --cached hello.txt
  3. rm 'hello.txt'

这个删除只是把文件从暂存区里面删除了,工作区里面还是有的,你用ls查看,发现文件还是在你工作区里面的

  1. root@ZJJ MINGW64 /f/projectDemo (master)
  2. $ ls
  3. hello.txt