什么情況
今天(2020-04-09)維護一個iOS項目,增加完需求走完測試流程后準(zhǔn)備在gitlab上做個版本,結(jié)果提交遇到如下問題:
! [rejected] master -> master (fetch first)
開始以為是倉庫沒有權(quán)限,于是登錄gitlab查看并不是權(quán)限的問題。
這個項目有些時日沒有改動了,沒有在意改動的問題,于是:
git pull-
git diff
改完有差異的文件后,clean Xcode工程,提交更改再push還是不行。
modified: ...... \*/UserInterfaceState.xcuserstate
才發(fā)現(xiàn)ignore文件居然沒有...于是添加了Objective-C的忽略文件。
各種ignore文件,點擊這里找
怎么做的
- 找到后創(chuàng)建ignore文件:
vim .gitignore把相應(yīng)的模板粘貼進去后保存.
或者touch .gitignore然后使用文本編輯器也可以。 - 忽略文件中追加以下內(nèi)容并保存:
xcuserdata/
*.xcbkptlist
*.xcuserstate
project.xcworkspace
xcuserdata
UserInterfaceState.xcuserstate
project.xcworkspace/
UserInterface.xcuserstate
3.提交忽略文件
當(dāng)前所在分支和遠程一一對應(yīng)的話push,pull不用指定分支
git add . ; git commit -m "fuck ignore file" ; git push
如果不放心文件有沒有都改完,可以 git pull ; git diff再查一遍修改完提交。
額外
- 回退到某個提交節(jié)點
- 查詢所有提交點:
git reflog - 回退:
git reset --hard HEAD@{n}這個n就是上面命令列舉出的數(shù)字
- 清除緩存區(qū)文件
git rm -r --cached .不要忘記這個點【.】