git 实战命令

2019-12-11  本文已影响0人  蜗牛Michael

一、实用命令

存储区域与状态:

  1. untracked 在本地且还未添加到git仓库管理, 提示如"Untracked files:"
Untracked files:
  (use "git add <file>..." to include in what will be committed)
    limao.txt
  1. unstaged 在本地且还未提交到暂存区,提示如"Changes not staged for commit:"
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   core/java/com/android/server/tv/TvInputManagerService.java
  1. staged 已经提交到暂存区可以commit, 提示如"Changes to be committed:"
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    modified:   Android.bp

从untracked状态变为unstaged状态
git restore --staged <file>...

从unstaged状态变为staged状态
git add <file>

将暂存区文件移出,从tracked变为untracked
git reset HEAD

从staged状态变为unstaged状态
git restore --staged <file>

从staged状态移除变为untracked状态,已经移出git控制范围了
git rm --cached <file>

将unstaged状态的文件修改删除
git restore <file>... // 与 git checkout --有同样的效果

删除unstaged文件的修改,已经add到staged的文件可以通过git restore --staged 恢复到unstaged状态
git checkout --

删除untracked的文件和文件目录
git clean -fd 文件和目录都会删除
git clean -f 只删除文件
git clean -fdn 添加-n参数不会真正删除,先看看would delete哪些文件和目录
git clean -xfd 连.gitignore文件也会一起删除

二、其他问题

pc@pc-PC MINGW64 ~/Desktop/项目笔记 (master)
$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        "1. \346\236\204\345\273\272\347\274\226\350\257\221\347\216\257\345\242\203.doc"
        algorithms.c
        queue.h
        test.cpp
        "\346\226\260\345\273\272 Microsoft Word \346\226\207\346\241\243.doc"
        "\346\265\201\351\200\232\351\200\232\351\201\223\345\256\275\345\272\246\350\256\241\347\256\227.png"
        "\347\256\227\346\263\225.txt"
        "\347\256\227\346\263\225\345\233\276.xls"
        "\347\256\227\346\263\225\345\233\276\344\276\213.png"
        "\347\256\227\346\263\225\347\254\224\350\256\260.doc"

解决方法:git config --global core.quotepath false

上一篇 下一篇

猜你喜欢

热点阅读