一、基本命令
1遮咖、初始化倉庫
git init
2滩字、配置倉庫
git config user.name xxx
git config user.email xxx
git config --global user.name xxx
git config --global user.email xxx
前兩種是配置在項目文件夾下,后兩個是配置全局的
3、指南使用
git help 子命令
退出 Q
下一頁 空格
上一頁 control+B
搜索 / 然后輸入要搜索的內(nèi)容后回車
二麦箍、常用指令
git status 查看文件狀態(tài)
git add 添加文件的暫存區(qū)
git commit 文件名稱 添加到本地倉庫
注意:如果沒有在commit后面加上 -m說明修改了什么漓藕,
會自動進(jìn)入vim界面,要求我們輸入修改信息
輸入修改信息步驟:
按鍵盤上的i
輸入信息
按鍵盤上的esc
輸入:wq然后回車
git config alias.別名 指令名
git config alias.st status 這種方法設(shè)置的別名是局部的
git config --global alias.st status 這樣設(shè)置是全局的
當(dāng)然了挟裂,不建議去起別名
git log 查看所有版本庫日志
git log 文件名 查看指定文件名的版本庫日志
git中的版本號是一個哈希值
git reflog 查看版本庫所有修改(包括提交和回退)
回退到相應(yīng)版本號(--hard表示強(qiáng)制)
git reset --hard HEAD 回到當(dāng)前版本享钞,放棄所有沒有提交的修改(git checkout 文件名 具有相同功能)
git reset --hard HEAD^ 回到上一個版本
git reset --hard HEAD~(3) 回到之前第三個修訂版本
get reset --head 版本號 回到相應(yīng)的版本號
(版本號是取前7位,可以通過git reflog指令獲得)
git diff 文件名 查看文件修改了什么地方
三诀蓉、遠(yuǎn)程倉庫配置
這里的遠(yuǎn)程倉庫可以是在本地的栗竖,也可以是在公司服務(wù)器上的。
1渠啤、git init --bare
注意:這個倉庫是用于管理代碼的狐肢,和git init生成的是不一樣的
Paste_Image.png
2、先克隆一份空的倉庫到本地
git clone /Users/username/Desktop/StudyCode/遠(yuǎn)程倉庫
3埃篓、忽略不需要加入版本控制的文件以及文件夾(這里的配置方法是在github上搜索的处坪,里面的內(nèi)容請搜索.gitignore)
.gitignore
echo -e "# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## Build generated
build/
DerivedData/
## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint
## Obj-C/Swift specific
*.hmap
*.ipa
# 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/
# 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://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md
fastlane/report.xml
fastlane/screenshots > .gitignore
注意:生成好的.gitignore文件一定要和.git隱藏文件夾在同一級目錄
4、將.gitignore添加到版本控制
git add .gitignore
git commit .gitignore -m"配置忽略文件"
5架专、新建項目
新建項目之后同窘,可以直接使用Xcode中的工具提交
source control -> commit 將代碼提交到本地倉庫
source control -> push 將代碼提交到遠(yuǎn)程倉庫