- 常見命令
1.初始化一個代碼倉庫
git init
2.如果使用git必須給git配置一個用戶名和郵箱
給當前的git倉庫配置一個用戶名和郵箱
git config user.name “XXX”
git config user.email “XXX”
配置一個全局的用戶名和郵箱
git config —global user.name “XXX”
git config —global user.email “XXX”
3.初始化項目
touch main.m : 創建了main.m
git add main.m : 將新添加的文件或者修改的文件添加到暫存區
git commit -m “初始化項目”
git add . : 將所有沒有被添加到暫存區或者代碼倉庫的文件添加到暫存區
注意:無論是新添加的文件或者修改的文件,都需要先通過add命令添加到暫存區中,之后再通過commit命令添加到本地倉庫中
4.查看文件的狀態 git status
紅色 : 新創建的文件或者被修改的文件,沒有被添加到暫存區
綠色 : 表示文件在暫存區,但是沒有被添加到本地倉庫中
5.給命令起別名
git config alias.st “status”
git config alias.ci “commit -m”
git config —global alias.st “status”
6.git刪除文件
git rm 文件名
7.查看版本號
git log
git reflog
git config --global alias.lg "log --color --graph -
8.git的版本號是由sha1算法生成40位的哈希值
9.版本回退
git reset —hard HEAD : 回退到當前的版本
git reset —hard HEAD^ : 回退到上一個版本
git reset —hard HEAD^^ : 回退到上上個版本
git reset —hard HEAD~100 : 回退到前100版本
git reset -hard 版本號(前5位)
- 團隊(共享版本庫)
1.初始項目
git init —bare
2.項目經理將共享版本庫的內容先下載下來
git clone 地址
3.添加需要忽略的文件
touch .gitignore
去github上搜索.gitignore->Objective-C
git add .gitignore
git commit -m “添加了需要忽略的文件”
4.項目經理初始化項目
git commit -m “初始化項目”—>提交到本地代碼倉庫
5.將項目push遠程倉庫中
git push origin
6.當源代碼管理是使用GIT,并且在Xcode進行多人開發的操作
注意:當使用GIT,項目中用到了靜態庫就不需要通過命令行進行添加
- 版本備份
1.1.0版本開發完成,之后對1.0版本進行備份
git tag -a weibo1.0 -m “這個是1.0版本” : 給某一個版本打上標簽
git tag : 查看所有的標簽
2.需要將1.0版本的標簽,push到服務器
git push origin weibo1.0
3.繼續開發2.0版本
4.發現1.0版本有bug,從標簽里面clone 1.0版本,從標簽創建一個fixbug分支,在分支中修復bug
git clone 共享版本庫
git checkout weibo1.0(標簽的名稱)
git checkout -b weibo1.1fixbug(分支名稱)
5.修復后的版本上傳AppStore/將1.0fixbug進行備份/將1.0fixbug版本和2.0版本進行合并
git tag -a weibo1.1 -m “這個是修復了1.0版本bug的1.1版本”
git tag
git push origin weibo1.1
將子分支中代碼合并到主分支,pull—>weibo1.1fixbug—>push master—>其它同事更新
6.刪除分支
git branch -r
git branch -r -d 分支名稱
- 將代碼托管至別人的服務器上
1.Github
創建Github上的倉庫
- HTTPS : http + SSL
- SSH : 公鑰和私鑰—>settings—>SSH Keys—>生成公鑰和私鑰
刪除代碼倉庫
可以給別人的代碼提比較功能/對別人的代碼重構:fork—>pull Request
issues : 給框架作者提問題
2.OSChina(Github上面項目不能私有化:交錢可以)
創建代碼倉庫
HTTPS/SSH
.gitignore不夠完整 : 手動添加完成
如果項目想要多人開發:管理—>成員管理—>添加成員:讓新人注冊一個OSChina
Last login: Fri Dec 25 08:27:25 on console
dllodeMac-mini-362:~ _Nidalee$ git clone https://git.oschina.net/nidalee/glone.git
Cloning into 'glone'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.
dllodeMac-mini-362:~ _Nidalee$ cd glone/
dllodeMac-mini-362:glone _Nidalee$** ls**
README.md
dllodeMac-mini-362:glone _Nidalee$ defaults write com.apple.finder AppleShowAllFiles -bool true
dllodeMac-mini-362:glone _Nidalee$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
"_Block\345\203\265\345\260\270\347\211\210/"
nothing added to commit but untracked files present (use "git add" to track)
dllodeMac-mini-362:glone _Nidalee$ git add -A
dllodeMac-mini-362:glone _Nidalee$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/project.pbxproj"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/project.xcworkspace/contents.xcworkspacedata"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/project.xcworkspace/xcuserdata/_Nidalee.xcuserdatad/UserInterfaceState.xcuserstate"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/xcuserdata/_Nidalee.xcuserdatad/xcschemes/_Block\345\203\265\345\260\270\347\211\210.xcscheme"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/xcuserdata/_Nidalee.xcuserdatad/xcschemes/xcschememanagement.plist"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/AppDelegate.h"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/AppDelegate.m"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/ArrayDataSource.h"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/ArrayDataSource.m"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/Assets.xcassets/AppIcon.appiconset/Contents.json"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/Base.lproj/LaunchScreen.storyboard"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/Base.lproj/Main.storyboard"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/Info.plist"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/ViewController.h"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/ViewController.m"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/main.m"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210Tests/Info.plist"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210Tests/_Block___Tests.m"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210UITests/Info.plist"
new file: "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210UITests/_Block___UITests.m"
dllodeMac-mini-362:glone _Nidalee$ git commit -m "提交了工程”
[master 2312b0d] 提交了工程
20 files changed, 1184 insertions(+)
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/project.pbxproj"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/project.xcworkspace/contents.xcworkspacedata"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/project.xcworkspace/xcuserdata/_Nidalee.xcuserdatad/UserInterfaceState.xcuserstate"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/xcuserdata/_Nidalee.xcuserdatad/xcschemes/_Block\345\203\265\345\260\270\347\211\210.xcscheme"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/xcuserdata/_Nidalee.xcuserdatad/xcschemes/xcschememanagement.plist"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/AppDelegate.h"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/AppDelegate.m"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/ArrayDataSource.h"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/ArrayDataSource.m"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/Assets.xcassets/AppIcon.appiconset/Contents.json"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/Base.lproj/LaunchScreen.storyboard"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/Base.lproj/Main.storyboard"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/Info.plist"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/ViewController.h"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/ViewController.m"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/main.m"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210Tests/Info.plist"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210Tests/_Block___Tests.m"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210UITests/Info.plist"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210UITests/_Block___UITests.m"
dllodeMac-mini-362:glone _Nidalee$ git pull
Already up-to-date.
dllodeMac-mini-362:glone _Nidalee$ git push
warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.
Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.
See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)
Username for 'https://git.oschina.net': nidalee
Password for 'https://nidalee@git.oschina.net': 密碼
Counting objects: 35, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (30/30), done.
Writing objects: 100% (35/35), 20.04 KiB | 0 bytes/s, done.
Total 35 (delta 4), reused 0 (delta 0)
To https://git.oschina.net/nidalee/glone.git
8368130..2312b0d master -> master
dllodeMac-mini-362:glone _Nidalee$