git的常规使用方法(iOS版)

好久没有接受新项目了,今天收到一个任务要开发一个新的appstore项目,由于太久没有开发,git命令已经略显生疏,所以今天复习一下。

首先,申请开发证书,这些就不说了,我们只说git相关的操作。
 

第一步 创建git仓库

git clone git@gitlab.com:zhikang_iOS/CloudLive.git
cd CloudLive
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
Existing folder
cd existing_folder
git init
git remote add origin git@gitlab.com:zhikang_iOS/CloudLive.git
git add .
git commit -m "Initial commit"
git push -u origin master
Existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin git@gitlab.com:zhikang_iOS/CloudLive.git
git push -u origin --all
git push -u origin --tags

 

 

第二步(实例操作)

 

 

 

kent-net:CloudLive_iOS kentj$ touch .gitignore 创建ignore文件,将下面代码粘贴到ignore文件中(仅iOS使用)
/*************************************************
 # Xcode
.DS_Store
*/build/*
        *.pbxuser
        !default.pbxuser
        *.mode1v3
        !default.mode1v3
        *.mode2v3
        !default.mode2v3
        *.perspectivev3
        !default.perspectivev3
        xcuserdata
        profile
        *.moved-aside
        DerivedData
        .idea/
        *.hmap
        *.xccheckout
        *.xcworkspace
        !default.xcworkspace
        
        #CocoaPods
        Pods
        !Podfile
        !Podfile.lock
  # Xcode
.DS_Store
*/build/*
        *.pbxuser
        !default.pbxuser
        *.mode1v3
        !default.mode1v3
        *.mode2v3
        !default.mode2v3
        *.perspectivev3
        !default.perspectivev3
        xcuserdata
        profile
        *.moved-aside
        DerivedData
        .idea/
        *.hmap
        *.xccheckout
        *.xcworkspace
        !default.xcworkspace
        
        #CocoaPods
        Pods
        !Podfile
        !Podfile.lock
  

 

/*************************************************

kent-net:CloudLive_iOS kentj$ git status 看下git状态如下?Your branch is up-to-date with 'origin/master'.Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: .DS_Store modified: CloudLive/.DS_Store modified: CloudLive/CloudLive.xcodeproj/project.xcworkspace/xcuserdata/kentj.xcuserdatad/UserInterfaceState.xcuserstateUntracked files: (use "git add <file>..." to include in what will be committed) .gitignoreno changes added to commit (use "git add" and/or "git commit -a")

 

        那我们怎么解决上述问题呢?        

第三步 解决.DS_Store的问题

         

       kent-net:CloudLive_iOS kentj$ find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
        rm '.DS_Store'
        rm 'CloudLive/.DS_Store'
        rm 'CloudLive/CloudLive/.DS_Store'
        rm 'CloudLive/CloudLive/Image/.DS_Store'
        rm 'CloudLive/CloudLive/Image/Mine/.DS_Store'
        rm 'CloudLive/CloudLive/Module/.DS_Store'
        kent-net:CloudLive_iOS kentj$ 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)
        
        deleted:    .DS_Store
        deleted:    CloudLive/.DS_Store
        deleted:    CloudLive/CloudLive/.DS_Store
        deleted:    CloudLive/CloudLive/Image/.DS_Store
        deleted:    CloudLive/CloudLive/Image/Mine/.DS_Store
        deleted:    CloudLive/CloudLive/Module/.DS_Store
        
        Changes not staged for commit:
        (use "git add <file>..." to update what will be committed)
        (use "git checkout -- <file>..." to discard changes in working directory)
        
        modified:   CloudLive/CloudLive.xcodeproj/project.xcworkspace/xcuserdata/kentj.xcuserdatad/UserInterfaceState.xcuserstate
        
        Untracked files:
        (use "git add <file>..." to include in what will be committed)
        
        .gitignore
        
        kent-net:CloudLive_iOS kentj$ git add --all
        kent-net:CloudLive_iOS kentj$ git commit -m '.DS_Store banished!'
        [master d6b40d5] .DS_Store banished!
        8 files changed, 28 insertions(+)
        delete mode 100644 .DS_Store
        create mode 100644 .gitignore
        delete mode 100644 CloudLive/.DS_Store
        delete mode 100644 CloudLive/CloudLive/.DS_Store
        delete mode 100644 CloudLive/CloudLive/Image/.DS_Store
        delete mode 100644 CloudLive/CloudLive/Image/Mine/.DS_Store
        delete mode 100644 CloudLive/CloudLive/Module/.DS_Store
        kent-net:CloudLive_iOS kentj$ git status
        On branch master
        Your branch is ahead of 'origin/master' by 1 commit.
        (use "git push" to publish your local commits)
        
        nothing to commit, working tree clean
        
     

 

第四步 提交修改,到这基本就大功告成了    

 

 

kent-net:CloudLive_iOS kentj$ git push
Counting objects: 13, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (12/12), done.
Writing objects: 100% (13/13), 1.31 KiB | 669.00 KiB/s, done.
Total 13 (delta 2), reused 0 (delta 0)
To gitlab.com:zhikang_iOS/CloudLive.git
2f7a7dc..d6b40d5  master -> m

 


       

 

 

 

 

第五步 那我们创建一个类来看下

kent-net:CloudLive_iOS kentj$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)

Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

new file:   CloudLive/CloudLive/FFViewController.h
new file:   CloudLive/CloudLive/FFViewController.m
new file:   CloudLive/CloudLive/FFViewController.xib

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified:   CloudLive/CloudLive.xcodeproj/project.pbxproj


大家已经看到,不会再出现除了项目代码相关意外的文件了

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值