为什么80%的码农都做不了架构师?>>>
在对自己的git仓库进行管理的时候,如果一下子要删除许多文件(不仅仅只是针对一个工程)。删除之后再次提交,会出现如下状态。
ZonetrydeMacBook-Pro:Ordinary-Works zonetry$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:(use "git add/rm ..." to update what will be committed)(use "git checkout -- ..." to discard changes in working directory)deleted: AllDemon/.DS_Storemodified: AllDemons/AllDemons.xcworkspace/xcuserdata/zonetry.xcuserdatad/UserInterfaceState.xcuserstatedeleted: ChainScrollView/ChainScrollView/Images.xcassets/AppIcon.appiconset/AppIcon@2x.pngdeleted: ChainScrollView/ChainScrollView/Images.xcassets/AppIcon.appiconset/AppIcon@3x.pngdeleted: ChainScrollView/ChainScrollView/Images.xcassets/AppIcon.appiconset/Contents.jsondeleted: ChainScrollView/ChainScrollView/Images.xcassets/Contents.jsondeleted: ChainScrollView/ChainScrollView/Images.xcassets/LaunchImage.launchimage/Contents.jsondeleted: ChainScrollView/ChainScrollView/Images.xcassets/LaunchImage.launchimage/Launch.pngdeleted: ChainScrollView/test/test/AppDelegate.hdeleted: ChainScrollView/test/test/AppDelegate.mdeleted: ChainScrollView/test/test/Assets.xcassets/AppIcon.appiconset/Contents.jsondeleted: ChainScrollView/test/test/Base.lproj/LaunchScreen.storyboarddeleted: ChainScrollView/test/test/Base.lproj/Main.storyboarddeleted: ChainScrollView/test/test/Info.plistdeleted: ChainScrollView/test/test/ViewController.hdeleted: ChainScrollView/test/test/ViewController.mdeleted: ChainScrollView/test/test/main.mdeleted: ChainScrollView/test/testTests/Info.plistdeleted: ChainScrollView/test/testTests/testTests.mdeleted: ChainScrollView/test/testUITests/Info.plistdeleted: ChainScrollView/test/testUITests/testUITests.mdeleted: LoginViewController.hdeleted: LoginViewController.mmodified: QQEmailAnimation/.DS_Storedeleted: SpaceManager/.DS_Storedeleted: SpaceManager/SpaceManager.xcodeproj/project.pbxprojdeleted: SpaceManager/SpaceManager.xcodeproj/project.xcworkspace/contents.xcworkspacedatadeleted: SpaceManager/SpaceManager.xcodeproj/project.xcworkspace/xcuserdata/zonetry.xcuserdatad/UserInterfaceState.xcuserstatedeleted: SpaceManager/SpaceManager.xcodeproj/xcuserdata/zonetry.xcuserdatad/xcschemes/SpaceManager.xcschemedeleted: SpaceManager/SpaceManager.xcodeproj/xcuserdata/zonetry.xcuserdatad/xcschemes/xcschememanagement.plistdeleted: SpaceManager/SpaceManager/main.mdeleted: Test/Test/AppDelegate.hdeleted: Test/Test/AppDelegate.mdeleted: Test/Test/Assets.xcassets/AppIcon.appiconset/Contents.jsondeleted: Test/Test/Base.lproj/LaunchScreen.storyboarddeleted: Test/Test/Base.lproj/Main.storyboarddeleted: Test/Test/Info.plistdeleted: Test/Test/ViewController.hdeleted: Test/Test/ViewController.mdeleted: Test/Test/main.mdeleted: Test/TestTests/Info.plistdeleted: Test/TestTests/TestTests.mdeleted: Test/TestUITests/Info.plistdeleted: Test/TestUITests/TestUITests.mdeleted: TestGame/TestGame.xcodeproj/project.pbxprojdeleted: TestGame/TestGame.xcodeproj/project.xcworkspace/contents.xcworkspacedatadeleted: TestGame/TestGame.xcodeproj/project.xcworkspace/xcuserdata/zonetry.xcuserdatad/UserInterfaceState.xcuserstatedeleted: TestGame/TestGame.xcodeproj/xcuserdata/zonetry.xcuserdatad/xcschemes/TestGame.xcschemedeleted: TestGame/TestGame.xcodeproj/xcuserdata/zonetry.xcuserdatad/xcschemes/xcschememanagement.plistdeleted: TestGame/TestGame/AppDelegate.hdeleted: TestGame/TestGame/AppDelegate.mdeleted: TestGame/TestGame/Assets.xcassets/AppIcon.appiconset/Contents.jsondeleted: TestGame/TestGame/Base.lproj/LaunchScreen.storyboarddeleted: TestGame/TestGame/Base.lproj/Main.storyboarddeleted: TestGame/TestGame/GameViewController.hdeleted: TestGame/TestGame/GameViewController.mdeleted: TestGame/TestGame/Info.plistdeleted: TestGame/TestGame/art.scnassets/ship.scndeleted: TestGame/TestGame/art.scnassets/texture.pngdeleted: TestGame/TestGame/main.mdeleted: TestGame/TestGameTests/Info.plistdeleted: TestGame/TestGameTests/TestGameTests.mdeleted: TestGame/TestGameUITests/Info.plistdeleted: TestGame/TestGameUITests/TestGameUITests.mdeleted: "\344\274\227\345\210\233\347\251\272\351\227\264.txt"deleted: "\345\256\271\346\230\223\345\277\230\350\256\260\347\232\204\344\270\200\344\272\233\344\270\234\350\245\277.txt"deleted: "\345\270\270\347\224\250\347\232\204\351\223\276\346\216\245\345\222\214tips.txt"deleted: "\346\234\211\345\276\227\347\240\224\347\251\266.txt"Untracked files:(use "git add ..." to include in what will be committed).DS_Storeno changes added to commit (use "git add" and/or "git commit -a")
这时候,即便你使用
git add *
git commit -m''
git pull
git push操作之后,再次检查状态,还是会出现这些状态,并且在你编译的时候会出现意想不到的那么多的警告。当看到这么多警告的时候,会很恶心。那么怎么解决掉对这些已经删除掉的文件的追踪了?
首先介绍一下工作区和暂存区概念:
工作区(Working Directory)就是你在电脑里能看到的目录。
版本库(Repository)
工作区有一个隐藏目录.git
,这个不算工作区,而是Git的版本库。
Git的版本库里存了很多东西,其中最重要的就是称为stage(或者叫index)的暂存区,还有Git为我们自动创建的第一个分支master
,以及指向master
的一个指针叫HEAD
。
前面讲了我们把文件往Git版本库里添加的时候,是分两步执行的:
第一步是用git add
把文件添加进去,实际上就是把文件修改添加到暂存区;
第二步是用git commit
提交更改,实际上就是把暂存区的所有内容提交到当前分支。
Git是如何跟踪修改的:每次修改,如果不add
到暂存区,那就不会加入到commit
中。
撤销修改
场景1:当你改乱了工作区某个文件的内容,想直接丢弃工作区的修改时,用命令git checkout -- file
。
场景2:当你不但改乱了工作区某个文件的内容,还添加到了暂存区时,想丢弃修改,分两步,第一步用命令git reset HEAD file
,就回到了场景1,第二步按场景1操作。
场景3:已经提交了不合适的修改到版本库时,想要撤销本次提交,git reset HEAD^
删除文件
在工作空间中删除了一个文件,Git知道你删除了文件,因此,工作区和版本库就不一致了,git status
命令会立刻告诉你哪些文件被删除了。
当工作区的文件必须得删除的时候,现在你有两个选择。
一是确实要从版本库中删除该文件,那就用命令git rm
删掉,并且git commit
:
另一种情况是删错了,因为版本库里还有呢,所以可以很轻松地把误删的文件恢复到最新版本: git checkout -- test.txt
其实是用版本库里的版本替换工作区的版本,无论工作区是修改还是删除,都可以“一键还原”。
在这里值得一提如果要删除版本库里一个文件里面的所有内容,请使用 git rm -r 文件名进行批量删除,比使用git rm 文件名的效率要高的多。
参考链接:http://www.cnblogs.com/zqlmmd/p/5541334.html