急需交给成功,add才能纳入git版本库管理

  1. 没辙切换分支

    $ git add .

    $ git checkout function

    error: Your local changes to the following files would be overwritten by checkout:

     SwiftLearn/ViewController.swift
    

    Please, commit your changes or stash them before you can switch branches.
    Aborting

  1. 不可能切换分支

    $ git add .

    $ git checkout function

    error: Your local changes to the following files would be overwritten by checkout:

     SwiftLearn/ViewController.swift
    

    Please, commit your changes or stash them before you can switch branches.
    Aborting

由来:ViewController.swift 中的文件提交后,commit
没有交到成功,供给交给成功,才能切换来其余支。

案由:ViewController.swift 中的文件提交后,commit
没有提交成功,要求提交成功,才能切换成别的支。

1 $  git commit -m "clear viewDidLoad"
2 
3 $ git checkout function
4 
5 
6 M    SwiftLearn.xcodeproj/project.pbxproj
7 M    SwiftLearn.xcodeproj/project.xcworkspace/xcuserdata/huanggang.xcuserdatad/UserInterfaceState.xcuserstate
8 Switched to branch 'function'
1 $  git commit -m "clear viewDidLoad"
2 
3 $ git checkout function
4 
5 
6 M    SwiftLearn.xcodeproj/project.pbxproj
7 M    SwiftLearn.xcodeproj/project.xcworkspace/xcuserdata/huanggang.xcuserdatad/UserInterfaceState.xcuserstate
8 Switched to branch 'function'

 

 

  1.1 git add 三种有别于

  1.1 git add 二种有别于

1      git add -A  提交所有变化
2 
3      git add -u  提交被修改(modified)和被删除(deleted)文件,不包括新文件(new)
4 
5       git add .  提交新文件(new)和被修改(modified)文件,不包括被删除(deleted)文件
1      git add -A  提交所有变化
2 
3      git add -u  提交被修改(modified)和被删除(deleted)文件,不包括新文件(new)
4 
5       git add .  提交新文件(new)和被修改(modified)文件,不包括被删除(deleted)文件

注意:git init后新加的文件,先要git
add才能纳入git版本库管理,不然新加文书为未跟踪状态。即:与 git
管理没用,不搭关系

专注:git init后新加的文本,先要git
add才能纳入git版本库管理,不然新加文书为未跟踪状态。即:与 git
管理没用,不搭关系

  1.2 git commit 区别

  1.2 git commit 区别

 

 

 1 //    对于已入版本库并且改动的文件,可以使用git commit -am "message",新文件需要先入版本库。
 2 //    也就是第一次你要 git add 将文件纳入版本库,后来再要修改不用 git add 了,直接用 git commit -am “123” 就可以了,将 git add省去了
 3 
 4 //   将一个文件 git add . 后,在对它修改
 5 
 6 //    第一种方法
 7 $    git commit -am "message"
 8 
 9 //    第二种方法
10 
11 $    git add .
12 
13 $    git commit -m "message"    
 1 //    对于已入版本库并且改动的文件,可以使用git commit -am "message",新文件需要先入版本库。
 2 //    也就是第一次你要 git add 将文件纳入版本库,后来再要修改不用 git add 了,直接用 git commit -am “123” 就可以了,将 git add省去了
 3 
 4 //   将一个文件 git add . 后,在对它修改
 5 
 6 //    第一种方法
 7 $    git commit -am "message"
 8 
 9 //    第二种方法
10 
11 $    git add .
12 
13 $    git commit -m "message"    

 

 

  1. 化解争辩后,合并遭遇难点

    $ git merge function

  1. 焚薮而田争论后,合并蒙受难题

    $ git merge function

Auto-merging 

SwiftLearn.xcodeproj/project.xcworkspace/xcuserdata/huanggang.xcuserdatad/UserInterfaceState.xcuserstate

CONFLICT (content): Merge conflict in 

SwiftLearn.xcodeproj/project.xcworkspace/xcuserdata/huanggang.xcuserdatad/UserInterfaceState.xcuserstate

Automatic merge failed; fix conflicts and then commit the result.

$ git branch -D function


//   当参数是 -d 时,对未合并的分支进行合并失败 

$ git branch -d feature-vulcan
error: The branch 'feature-vulcan' is not fully merged.
If you are sure you want to delete it, run 'git branch -D feature-vulcan'.
//   销毁失败。Git友情提醒,feature-vulcan分支还没有被合并,如果删除,将丢失掉修改,如果要强行删除,需要使用命令git branch -D feature-vulcan。

//   现在我们强行删除:

$ git branch -D feature-vulcan
Deleted branch feature-vulcan (was 756d4af).     
Auto-merging 

SwiftLearn.xcodeproj/project.xcworkspace/xcuserdata/huanggang.xcuserdatad/UserInterfaceState.xcuserstate

CONFLICT (content): Merge conflict in 

SwiftLearn.xcodeproj/project.xcworkspace/xcuserdata/huanggang.xcuserdatad/UserInterfaceState.xcuserstate

Automatic merge failed; fix conflicts and then commit the result.

$ git branch -D function


//   当参数是 -d 时,对未合并的分支进行合并失败 

$ git branch -d feature-vulcan
error: The branch 'feature-vulcan' is not fully merged.
If you are sure you want to delete it, run 'git branch -D feature-vulcan'.
//   销毁失败。Git友情提醒,feature-vulcan分支还没有被合并,如果删除,将丢失掉修改,如果要强行删除,需要使用命令git branch -D feature-vulcan。

//   现在我们强行删除:

$ git branch -D feature-vulcan
Deleted branch feature-vulcan (was 756d4af).     

 

 

  1. 联合后只剩3个 master 分支,切换来另三个分支上出错

    1 $ git checkout -b develop
    2
    3 xxx needs merge
    4 error: you need to resolve your current index first
    5
    6 // 唯有1个分支了,还怎么统一,恐怕没交给,提交了下,成功了
    7 $ git branch
    8 * master
    9
    10 $ git commit -am “123”
    11 [master 3cadb9c] 123
    12
    13 $ git checkout -b develop
    14 Switched to a new branch ‘develop’

  1. 集合后只剩八个 master 分支,切换成另2个拨出上出错

    1 $ git checkout -b develop
    2
    3 xxx needs merge
    4 error: you need to resolve your current index first
    5
    6 // 唯有一个拨出了,还怎么统一,恐怕没交给,提交了下,成功了
    7 $ git branch
    8 * master
    9
    10 $ git commit -am “123”
    11 [master 3cadb9c] 123
    12
    13 $ git checkout -b develop
    14 Switched to a new branch ‘develop’

须求对联合后的道岔实行付出,不然出错

亟待对联合后的分层进行提交,不然出错

 

 

4.重复合并争论

4.重复合并争持

经常来说,你是把您付出的那条分支 develop 合并到 master ,不过当你把
master 合并到 你付出的 develop 上时,会报错在巅峰,错误为冲突。

正规来说,你是把你付出的那条分支 develop 合并到 master ,然则当您把
master 合并到 你付出的 develop 上时,会报错在顶峰,错误为争持。

 1 $ git checkout -b developEnum
 2 
 3 $ git add .
 4 
 5 $ git commit -am "EnumFolderAndSwift"
 6 
 7 $ git merge master
 8 
 9 $ git checkout master
10 
11 $ git status
12 
13 On branch master
14 Your branch is ahead of 'origin/master' by 6 commits.
15 
16 $ git checkout developEnum
17 
18 $ git merge master
19 
20 error: Your local changes to the following files would be overwritten by merge:
21     SwiftLearn.xcodeproj/project.xcworkspace/xcuserdata/huanggang.xcuserdatad/UserInterfaceState.xcuserstate
22 
23 Please, commit your changes or stash them before you can merge.
24 
25 Aborting
26 
27 $ git commit -am "enum1"
28 
29 [developEnum 24d2739] enum1
30  1 file changed, 0 insertions(+), 0 deletions(-)
31 
32 $ git merge master 
33 
34 warning: Cannot merge binary files: SwiftLearn.xcodeproj/project.xcworkspace/xcuserdata/huanggang.xcuserdatad/UserInterfaceState.xcuserstate (HEAD vs. master)
35 
36 Auto-merging SwiftLearn.xcodeproj/project.xcworkspace/xcuserdata/huanggang.xcuserdatad/UserInterfaceState.xcuserstate
37 
38 CONFLICT (content): Merge conflict in SwiftLearn.xcodeproj/project.xcworkspace/xcuserdata/huanggang.xcuserdatad/UserInterfaceState.xcuserstate
39 
40 Automatic merge failed; fix conflicts and then commit the result.
 1 $ git checkout -b developEnum
 2 
 3 $ git add .
 4 
 5 $ git commit -am "EnumFolderAndSwift"
 6 
 7 $ git merge master
 8 
 9 $ git checkout master
10 
11 $ git status
12 
13 On branch master
14 Your branch is ahead of 'origin/master' by 6 commits.
15 
16 $ git checkout developEnum
17 
18 $ git merge master
19 
20 error: Your local changes to the following files would be overwritten by merge:
21     SwiftLearn.xcodeproj/project.xcworkspace/xcuserdata/huanggang.xcuserdatad/UserInterfaceState.xcuserstate
22 
23 Please, commit your changes or stash them before you can merge.
24 
25 Aborting
26 
27 $ git commit -am "enum1"
28 
29 [developEnum 24d2739] enum1
30  1 file changed, 0 insertions(+), 0 deletions(-)
31 
32 $ git merge master 
33 
34 warning: Cannot merge binary files: SwiftLearn.xcodeproj/project.xcworkspace/xcuserdata/huanggang.xcuserdatad/UserInterfaceState.xcuserstate (HEAD vs. master)
35 
36 Auto-merging SwiftLearn.xcodeproj/project.xcworkspace/xcuserdata/huanggang.xcuserdatad/UserInterfaceState.xcuserstate
37 
38 CONFLICT (content): Merge conflict in SwiftLearn.xcodeproj/project.xcworkspace/xcuserdata/huanggang.xcuserdatad/UserInterfaceState.xcuserstate
39 
40 Automatic merge failed; fix conflicts and then commit the result.

 

 

 

 

斩草除根办法,将已联合到 developEnumm 分支上的文本作为 master
,将其他无法集合的支行删除掉,用 git branch -d <分支名>
是不行的,因为会唤醒您有争执之类的,用强制删除 git branch -D
<分支名>

消除措施,将已联合到 developEnumm 分支上的公文作为 master
,将其余不能够集合的道岔删除掉,用 git branch -d <分支名>
是那多少个的,因为会提示您有争辨之类的,用强制删除 git branch -D
<分支名>

 

 

 1 $ git branch
 2 
 3  develop
 4 * developEnum
 5   master
 6 
 7 $ git branch -d develop
 8 
 9 error: The branch 'develop' is not fully merged.
10 If you are sure you want to delete it, run 'git branch -D develop'.
11 
12 $ git branch -D develop
13 
14 Deleted branch develop (was 1147815).
15 
16 // 将代码上传到服务器
17 
18 $ git push origin developEnum
19 
20 Counting objects: 77, done.
21 Delta compression using up to 4 threads.
 1 $ git branch
 2 
 3  develop
 4 * developEnum
 5   master
 6 
 7 $ git branch -d develop
 8 
 9 error: The branch 'develop' is not fully merged.
10 If you are sure you want to delete it, run 'git branch -D develop'.
11 
12 $ git branch -D develop
13 
14 Deleted branch develop (was 1147815).
15 
16 // 将代码上传到服务器
17 
18 $ git push origin developEnum
19 
20 Counting objects: 77, done.
21 Delta compression using up to 4 threads.

 

 

 

 

  1. 从服务器拉取不相同分支报错

    1 $ git pull
    2
    3 error: Pull is not possible because you have unmerged files.
    4 hint: Fix them up in the work tree, and then use ‘git add/rm
    5 hint: as appropriate to mark resolution and make a commit.
    6 fatal: Exiting because of an unresolved conflict.
    7
    8 $ git branch
    9
    10 * developEnum
    11
    12 $ git commit -am “over1”
    13
    14 [developEnum 545beae] over1
    15
    16 $ git pull
    17
    18 There is no tracking information for the current branch.
    19 Please specify which branch you want to merge with.
    20
    21 // 报错原因是绝非点名地点master和远程origin/master的连天,执行git branch –set-upstream master origin/master,设置链接
    22
    23 $ git branch –set-upstream developEnum origin/developEnum
    24
    25 The –set-upstream flag is deprecated and will be removed. Consider using –track or –set-upstream-to
    26 Branch developEnum set up to track remote branch developEnum from origin.
    27
    28 // 添加–set-upstream-to,那是肯比老方法,不对了
    29 $ git branch –set-upstream-to developEnum origin/developEnum
    30 fatal: branch ‘origin/developEnum’ does not exist //不设有
    31
    32 // 成功了!
    33 $ git pull
    34 Already up-to-date.
    35
    36 // 第贰种 :推送代码到服务器,本地分支在 developEnum上
    37 $ git push origin developEnum
    38
    39 Counting objects: 14, done.
    40 Delta compression using up to 4 threads.
    41
    42 // 第而种 :推送代码到服务器,git push origin local_branch:remote_branch,这么些操作,local_branch必须为你本地存在的分段,remote_branch为远程分支,假使remote_branch不存在则会自行成立分支。git push origin :remote_branch,local_branch留空的话则是去除远程remote_branch分支

    43 $ git push origin developEnum:master
    44
    45 Everything up-to-date

  1. 从服务器拉取差别分支报错

    1 $ git pull
    2
    3 error: Pull is not possible because you have unmerged files.
    4 hint: Fix them up in the work tree, and then use ‘git add/rm
    5 hint: as appropriate to mark resolution and make a commit.
    6 fatal: Exiting because of an unresolved conflict.
    7
    8 $ git branch
    9
    10 * developEnum
    11
    12 $ git commit -am “over1”
    13
    14 [developEnum 545beae] over1
    15
    16 $ git pull
    17
    18 There is no tracking information for the current branch.
    19 Please specify which branch you want to merge with.
    20
    21 // 报错原因是不曾点名地点master和远程origin/master的连天,执行git branch –set-upstream master origin/master,设置链接
    22
    23 $ git branch –set-upstream developEnum origin/developEnum
    24
    25 The –set-upstream flag is deprecated and will be removed. Consider using –track or –set-upstream-to
    26 Branch developEnum set up to track remote branch developEnum from origin.
    27
    28 // 添加–set-upstream-to,那是肯比老方法,不对了
    29 $ git branch –set-upstream-to developEnum origin/developEnum
    30 fatal: branch ‘origin/developEnum’ does not exist //不存在
    31
    32 // 成功了!
    33 $ git pull
    34 Already up-to-date.
    35
    36 // 第三种 :推送代码到服务器,本地分支在 developEnum上
    37 $ git push origin developEnum
    38
    39 Counting objects: 14, done.
    40 Delta compression using up to 4 threads.
    41
    42 // 第而种 :推送代码到服务器,git push origin local_branch:remote_branch,那几个操作,local_branch必须为您本地存在的分层,remote_branch为远程分支,要是remote_branch不存在则会自行制造分支。git push origin :remote_branch,local_branch留空的话则是去除远程remote_branch分支

    43 $ git push origin developEnum:master
    44
    45 Everything up-to-date

 

 

  1. 从服务器拉代码有三种办法
  1. 从服务器拉代码有二种格局

  6.1  本地分支与服务器的支行相同,才能拉代码

  6.1  本地分支与服务器的分支相同,才能拉代码

 1 $ git checkout -b master
 2 Switched to a new branch 'master'
 3 
 4 //    报错
 5 $ git pull
 6 There is no tracking information for the current branch.
 7 Please specify which branch you want to merge with.
 8 
 9 //    正确从服务器拉代码或者 git fetch origin xxx 等价于  git pull origin xxx
10 $ git pull origin master
11 From github.com:WindAndSand/SwiftLearn
12  * branch            master     -> FETCH_HEAD
13 Already up-to-date.
14 
15 $ git branch
16   developEnum
17 * master
18 
19 //    推送本地分支到远程仓库
20 
21 $ git push origin master
22 Total 0 (delta 0), reused 0 (delta 0)
23 To git@github.com:WindAndSand/SwiftLearn.git
 1 $ git checkout -b master
 2 Switched to a new branch 'master'
 3 
 4 //    报错
 5 $ git pull
 6 There is no tracking information for the current branch.
 7 Please specify which branch you want to merge with.
 8 
 9 //    正确从服务器拉代码或者 git fetch origin xxx 等价于  git pull origin xxx
10 $ git pull origin master
11 From github.com:WindAndSand/SwiftLearn
12  * branch            master     -> FETCH_HEAD
13 Already up-to-date.
14 
15 $ git branch
16   developEnum
17 * master
18 
19 //    推送本地分支到远程仓库
20 
21 $ git push origin master
22 Total 0 (delta 0), reused 0 (delta 0)
23 To git@github.com:WindAndSand/SwiftLearn.git

 

 

   6.2 建立地点分支与服务器分支相连

   6.2 建立地点分支与服务器分支相连

//    查看远程分支
$ git branch -r

  origin/baseOne
  origin/developEnum
  origin/master

$ git branch
  developEnum
* master

//    本地dev分支与远程origin/dev分支的链接
$ git branch --set-upstream developEnum origin/developEnum

//    拉取代码
$ git pull
From .
 * branch            developEnum -> FETCH_HEAD
Already up-to-date.
//    查看远程分支
$ git branch -r

  origin/baseOne
  origin/developEnum
  origin/master

$ git branch
  developEnum
* master

//    本地dev分支与远程origin/dev分支的链接
$ git branch --set-upstream developEnum origin/developEnum

//    拉取代码
$ git pull
From .
 * branch            developEnum -> FETCH_HEAD
Already up-to-date.

   6.2
在当地建3个分段与服务器进行映射,前提本地没有三个与长途服务器相同的分支

   6.2
在地头建二个分段与服务器实行映射,前提本地没有一个与远程服务器相同的分层

$ git branch -r

  origin/HEAD -> origin/master
  origin/MataRelease
  origin/a
  origin/correct
  origin/customupload
  origin/dev
  origin/dev-swift3.2
  origin/dev1.1.2
  origin/dev1.2
  origin/feature/adjust-font
  origin/feature/send-file
  origin/master
  origin/pjsip
  origin/rageshake
  origin/reconnect
  origin/release
  origin/sslsocket
  origin/tls
  origin/zimsdk


$ git branch -d adjust-font
Deleted branch adjust-font (was 2191110).

//    与远程服务器建立映射
$ git checkout -b adjust-font origin/feature/adjust-font
M    submodules/zimsdk
Branch adjust-font set up to track remote branch feature/adjust-font from origin.
Switched to a new branch 'adjust-font'

$ git pull
Already up-to-date.

$ git branch
* adjust-font
  master
$ git branch -r

  origin/HEAD -> origin/master
  origin/MataRelease
  origin/a
  origin/correct
  origin/customupload
  origin/dev
  origin/dev-swift3.2
  origin/dev1.1.2
  origin/dev1.2
  origin/feature/adjust-font
  origin/feature/send-file
  origin/master
  origin/pjsip
  origin/rageshake
  origin/reconnect
  origin/release
  origin/sslsocket
  origin/tls
  origin/zimsdk


$ git branch -d adjust-font
Deleted branch adjust-font (was 2191110).

//    与远程服务器建立映射
$ git checkout -b adjust-font origin/feature/adjust-font
M    submodules/zimsdk
Branch adjust-font set up to track remote branch feature/adjust-font from origin.
Switched to a new branch 'adjust-font'

$ git pull
Already up-to-date.

$ git branch
* adjust-font
  master

 

 

 

 

7. 将本地的代码推送到服务器

7. 将地点的代码推送到服务器

 1 $ cd /Users/用户名/Desktop/
 2 
 3 $ cd GitDemo
 4 
 5 $ git init
 6 
 7 $ git add --all    //提交到暂存区
 8 
 9 $ git commit -m "提交文件到 master"
10 
11 $ git remote add origin git@github.com:WindAndSand/GitTest.git
12 
13 $ fatal: remote origin already exists.    //不是错误,告诉你 origin 已存在
14 
15 $ git push origin master:master 
16 
17 //    出现错误,制取其中一个如:
18 
19 $ Updates were rejected because the remote contains work that you do
20 
21 //    原因:造成这个错误是因为我在github上修改了自己的文件,在上传本地文件之前没有把github上的文件拉倒本地。意思是本地和远程的文件应该合并后才能上传本地的新文件
22 
23 //    先拉下来,会自动合并的(不用操心)
24 
25 $ git pull origin master  //若远程仓库不存在其他文件,空空的什么也没有,不用敲,当然不包括 REAMD
26 
27 //    再上传
28 
29 $ git push -u origin master
 1 $ cd /Users/用户名/Desktop/
 2 
 3 $ cd GitDemo
 4 
 5 $ git init
 6 
 7 $ git add --all    //提交到暂存区
 8 
 9 $ git commit -m "提交文件到 master"
10 
11 $ git remote add origin git@github.com:WindAndSand/GitTest.git
12 
13 $ fatal: remote origin already exists.    //不是错误,告诉你 origin 已存在
14 
15 $ git push origin master:master 
16 
17 //    出现错误,制取其中一个如:
18 
19 $ Updates were rejected because the remote contains work that you do
20 
21 //    原因:造成这个错误是因为我在github上修改了自己的文件,在上传本地文件之前没有把github上的文件拉倒本地。意思是本地和远程的文件应该合并后才能上传本地的新文件
22 
23 //    先拉下来,会自动合并的(不用操心)
24 
25 $ git pull origin master  //若远程仓库不存在其他文件,空空的什么也没有,不用敲,当然不包括 REAMD
26 
27 //    再上传
28 
29 $ git push -u origin master

 

 

 

 

 

 

8. 拉取远程服务器的文书

8. 拉取远程服务器的公文

  命令:

  命令:

1 git clone "地址";
1 git clone "地址";

 

 

 
 注意:有贰个陷阱,工程中还有子模块,不然会报错,如错误:( MessagesMissing
dependency target “zimsdkoc (from
zimsdkoc.xcodeproj)”
%22&tn=84053098_3_dg&ie=utf-8)),无法改动;

 
 注意:有3个陷阱,工程中还有子模块,不然会报错,如错误:( MessagesMissing
dependency target “zimsdkoc (from
zimsdkoc.xcodeproj)”
%22&tn=84053098_3_dg&ie=utf-8)),无法改动;

  下载子模块的通令:

  下载子模块的吩咐:

1 git submodule  update --init --recursive
1 git submodule  update --init --recursive

 

 

  子模块和类库的概念:http://blog.csdn.net/sinat\_16714231/article/details/52797845;

  子模块和类库的定义:http://blog.csdn.net/sinat\_16714231/article/details/52797845;

  若提醒版本更新可以忽略下载:

  若提醒版本更新可以忽略下载:

1  pod install --verbose
1  pod install --verbose

   

   

相关文章