git status查看文件的状态

提要

通过git status查看文件的状态时,出现了一些如下的提示:

jidfj@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git status
On branch master
Your branch is behind 'origin/master' by 8 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

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:   SceneModule/SceneComponent/layoutListwidget.cpp
        modified:   ZhuShouMainFrame.pro.user

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        ZhuShouMainFrame.pro.user.546ac14

no changes added to commit (use "git add" and/or "git commit -a")

这时对于新手就不知该如何操作,其实只需根据提示,结合自己的需求,输入指令。

实现

像上面出现的情况,我是在更新了项目之后出现了这样的问题,于是金国一系列的查找终于了解了一些。
支队上面的提示,我想着添加修改到gitlab上,于是我输入了指令:git add 。如下面所示:

dhusd@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git add  SceneModule/SceneComponent/layoutListwidget.cpp

banli@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git pull
error: Your local changes to the following files would be overwritten by merge:
        SceneModule/SceneComponent/layoutListwidget.cpp
Please commit your changes or stash them before you merge.
error: Your local changes to the following files would be overwritten by merge:
        ZhuShouMainFrame.pro.user
Please commit your changes or stash them before you merge.
error: The following untracked working tree files would be overwritten by merge:
        ZhuShouMainFrame.pro.user.546ac14
Please move or remove them before you merge.
Aborting
Updating 77e467a..e1727c0

这时并没有提交更改到暂存区,也就是提交没有结束,若想将修改提交到gitlab上,需要继续输入指令:git commit -a -m “描述”。然后紧接着输入git push指令。才能将修改提交上去。
但是我并不想提交这次修改,所以可以采用下面的指令:
git restore


sdsf@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git restore  ZhuShouMainFrame.pro.user

sdsf@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git pull
error: Your local changes to the following files would be overwritten by merge:
        SceneModule/SceneComponent/layoutListwidget.cpp
Please commit your changes or stash them before you merge.
error: The following untracked working tree files would be overwritten by merge:
        ZhuShouMainFrame.pro.user.546ac14
Please move or remove them before you merge.
Aborting
Updating 77e467a..e1727c0

sdsf@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git status
On branch master
Your branch is behind 'origin/master' by 8 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   SceneModule/SceneComponent/layoutListwidget.cpp

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        ZhuShouMainFrame.pro.user.546ac14

将在工作区但不在暂存区的文件撤销修改,文件的内容恢复到没有修改之前。就是将本地这一次不应该上传已经的文件撤销,但是可以看到还是有一些文件的状态还是不怎么正常。
紧接着执行指令:

sdcs@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git add ZhuShouMainFrame.pro.user.546ac14

sdcs@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git pull
error: Your local changes to the following files would be overwritten by merge:
        SceneModule/SceneComponent/layoutListwidget.cpp
Please commit your changes or stash them before you merge.
Aborting
Updating 77e467a..e1727c0

sdcs@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git status
On branch master
Your branch is behind 'origin/master' by 8 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   SceneModule/SceneComponent/layoutListwidget.cpp
        new file:   ZhuShouMainFrame.pro.user.546ac14

先将文件ZhuShouMainFrame.pro.user.546ac14合并,之后更新了代码,然后又查看了文件的状态,可以看到还是有文件状态不怎么看着舒服,接着输入下面的指令。

sddi@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git restore  --staged SceneModule/SceneComponent/layoutListwidget.cpp

sddi@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git status
On branch master
Your branch is behind 'origin/master' by 8 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   ZhuShouMainFrame.pro.user.546ac14

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:   SceneModule/SceneComponent/layoutListwidget.cpp

上面的提示指出可以通过忽略本次文件在工作区的更改,于是我就忽略了。输入指令:

sdss@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git restore SceneModule/SceneComponent/layoutListwidget.cpp

sada@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git status
On branch master
Your branch is behind 'origin/master' by 8 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   ZhuShouMainFrame.pro.user.546ac14


sada@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git pull
Updating 77e467a..e1727c0
Fast-forward
 DecoderPainter/playwidget.cpp                      |   4 +-
 LoginManager/LoginManager.cpp                      |  14 +-
 LoginManager/LoginManager.h                        |   1 +
 MessageCenter/messagecenter.cpp                    |  12 +-
 MessageCenter/messagecenter.h                      |   4 +-
 NetWork/networkclienthttp.cpp                      |   7 +
 NetWork/networkclienthttp.h                        |   2 +-
 SIgnalList/listwindows.cpp                         |   4 +-
 .../qss/psblack/SignalList.css                     |   0
 SIgnalList/qssFile.qrc                             |   1 +
 SceneModule/SceneComponent/layoutListwidget.cpp    |   6 +-
 ScreenPreview/priviewnavigator.cpp                 |  52 ++--
 ScreenPreview/signalwin.cpp                        |  28 +-
 SourceControl/controlevent.cpp                     |   1 -
 TimeLine/mainframe.h                               |   7 +-
 ZhuShouMainFrame.pro.user                          |  18 +-
 ZhuShouMainFrame.pro.user.546ac14                  | 337 +++++++++++++++++++++
 ZhuShouMainFrame.ui                                |  10 +-
 18 files changed, 430 insertions(+), 78 deletions(-)
 rename "\351\234\200\350\246\201\346\267\273\345\212\240\345\210\260\350\277\220\350\241\214\347\233\256\345\275\225\347\232\204\346\226\207\344\273\266/SignalList.css" => SIgnalList/qss/psblack/SignalList.css (100%)
 create mode 100644 ZhuShouMainFrame.pro.user.546ac14

sada@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

sada@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git pull
Already up to date.

经过一顿乱操作,可以看到现在查看代码的状态的时候是正常的状态,看着顺眼了。
作者也是第一次使用gitlab很多不懂,还望指教。

总结

1.git restore
撤销本次在工作区但是没有在暂存区的文件内容的更改。
2.git restore --staged
将暂存区的文件从暂存区撤出,不改变文件的内容。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

肩上风骋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值