一、git命令语句
二、如何设置.gitignore文件。
-
首先你要给你创建的项目设置.gitignore忽略文件,防止把无关的文件上传到远程仓库(gitlab或者github)上,从而造成不必要的错误。
-
如何设置.gitignore忽略文件步骤。
1.在终端进入所在项目上,然后创建gitignore文件 首先cd 该目录文件 2.先创建touch .gitignore, 打开open .gitignore, 粘贴进去,(github.com/github/giti…) 网站上找到Objective-c或者swift忽略文件 保存关闭, 添加到缓存区,git add .gitignore 提交git commit -m "添加了.gitignore文件" 推送git push
以上就完成了如何设置忽略文件。
亲,我也给你准备了所需的忽略文件哦!!!!(是不是很nice)
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## User settings
xcuserdata/
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
## Obj-C/Swift specific
*.hmap
## App packaging
*.ipa
*.dSYM.zip
*.dSYM
# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
#
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
Carthage/Build/
# fastlane
#
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output
# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode
iOSInjectionProject/
三、自己在git上遇到的问题及其我是如何解决
-
我在gitlab上创建分支后,我在xcode上想把代码上传我创建的分支上,我百度了一半天发现是自己没有去刷新状态。直接在xcode的Source Control上点击fetch change。就可以看见并上传到所创建的分支上。
-
当同事提交代码使,我pull时发生了很大的问题。怎么都不能去pull下来。遇见的问题是这样,我原来没有设置忽略文件,一直把UserInterfaceState.xcuserstate等无效文件上传了上去,和同事的上传的这些文件发生了冲突,导致在xcode上无法pull。我百度了很久,我在看见某些文章之后,突然知道到了如何去解决。
首先然后找到忽略文件退回工作区在放进忽略文件中忽略 使用git rm --cached + ProjectFolder.xcodeproj/project.xcworkspace/xcuserdata/myUserName.xcuserdatad/UserInterfaceState.xcuserstate 挨个删除无效文件,然后设置忽略文件,即可解决无效文件产生的问题。 最后pull即可。
3.当同事上传了自己的代码到远程仓库时,而自己写的代码需要保存,先commit到本地仓库,然后pull文件,最后在push即可。
4.当你使用git commit -m "message"命令时,如果你想修改message的内容,输入git commit --amend 进入vim模式,然后点击“ i ”进入编辑模式,你就可以开始修改内容了。修改完成之后按esc健,退出编辑模式。 最重要的一步,输入“ :”,然后下方会出来:。输入wq命令强制保存 。至此修改成功。 如果你不熟悉vim模式,你可以去到zhuanlan.zhihu.com/p/61277913
四、使用gitlab初始化项目
第一次使用gitlab来上传确实不会,问了公司的大佬,大佬来我这电脑敲的同时,我记住了怎么初始化项目的过程。
我自己第一次clone项目的时候,出现了:destination path 'ios' already exists and is not an empty directory.的问题。我翻译了之后,说的是已经存在,但是我并没有在目录文件中找到之后,上网百度之后,也不知道。问了大佬。在大佬在我的电脑上敲打的时候,我明白了自己的最大的问题。居然自己把clone的代码直接拉到桌面上,导致根本不可能找到。这就是问题的出现原因。
解决方法,直接在桌面上建立一个文件夹来管理自己的代码存放的地方。
cd 项目
git clone http:// -----> url地址
cd testDemo-lwy
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
//切换branch
git branch -a
git checkout -b test origin/test
按照上面的步骤在文件里面写就行,注意点:
- 需要注意的是弄好git的时候,需要添加忽略文件。
- 然后切换到开发dev分支。
- 上传项目文件到git,可以直接复制原来的项目基础框架到该项目文件下。然后上传就行了。
五、总结
- 第一次写文章,也没有啥经验,哈哈哈哈。
- 因为热爱,所以深研。