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

来源:互联网 发布:河南云和软件科技 编辑:程序博客网 时间:2024/05/16 11:45
好久没有接受新项目了,今天收到一个任务要开发一个新的appstore项目,由于太久没有开发,git命令已经略显生疏,所以今天复习一下。

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

第一步 创建git仓库

git clone git@gitlab.com:zhikang_iOS/CloudLive.gitcd CloudLivetouch README.mdgit add README.mdgit commit -m "add README"git push -u origin masterExisting foldercd existing_foldergit initgit remote add origin git@gitlab.com:zhikang_iOS/CloudLive.gitgit add .git commit -m "Initial commit"git push -u origin masterExisting Git repositorycd existing_repogit remote rename origin old-origingit remote add origin git@gitlab.com:zhikang_iOS/CloudLive.gitgit push -u origin --allgit 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  
/*************************************************
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 pushCounting 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.git2f7a7dc..d6b40d5  master -> m


       

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

kent-net:CloudLive_iOS kentj$ git statusOn branch masterYour 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.hnew file:   CloudLive/CloudLive/FFViewController.mnew file:   CloudLive/CloudLive/FFViewController.xibChanges 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

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


 
原创粉丝点击