提要
通过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.cppmodified: ZhuShouMainFrame.pro.userUntracked files:(use "git add <file>..." to include in what will be committed)ZhuShouMainFrame.pro.user.546ac14no 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.cppbanli@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.usersdsf@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..e1727c0sdsf@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.cppUntracked 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.546ac14sdcs@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..e1727c0sdcs@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.cppnew file: ZhuShouMainFrame.pro.user.546ac14
先将文件ZhuShouMainFrame.pro.user.546ac14合并,之后更新了代码,然后又查看了文件的状态,可以看到还是有文件状态不怎么看着舒服,接着输入下面的指令。
sddi@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git restore --staged SceneModule/SceneComponent/layoutListwidget.cppsddi@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.546ac14Changes 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.cppsada@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.546ac14sada@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git pull
Updating 77e467a..e1727c0
Fast-forwardDecoderPainter/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 | 0SIgnalList/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.546ac14sada@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 cleansada@DESKTOP-2DAKPIL MINGW64 /g/excise/zhushouProject/ZhuShou (master)
$ git pull
Already up to date.
经过一顿乱操作,可以看到现在查看代码的状态的时候是正常的状态,看着顺眼了。
作者也是第一次使用gitlab很多不懂,还望指教。
总结
1.git restore
撤销本次在工作区但是没有在暂存区的文件内容的更改。
2.git restore --staged
将暂存区的文件从暂存区撤出,不改变文件的内容。