文章目录
  1. 1. 当 Xcode 遇上 Git,迸发出爱的火花
    1. 1.1. 三种解决方法:

当 Xcode 遇上 Git,迸发出爱的火花

当使用 Xcode 自带的 Git 进行版本控制,我们可能会遇到 The working copy “(工程名)” has uncommitted changes. Try committing or discarding the changes.

image

分析原因:可能是 Git 追踪了与系统用户相关的某个文件,而这个文件时刻在变化。

三种解决方法:

0、Cannot pull、merge、swtich branch,在项目目录下执行以下命令:

1
2
3
$ git rm --cached *.xcuserstate //移除索引or代码库中的文件
$ git rm --cached *.xcuserdata //从代码库中移除相应的跟踪文件
$ git commit -m "提交" //一定要进行提交,提交到仓库。

1、Uncommited changes vs nothing to commitcd 到项目目录下(这个方法,有风险!!!):

1
2
3
4
$ git reset --hard
$ git status
$ git commit -m "此方法有风险,请慎重。"
重启Xcode

原文回答:

Okay, so I fixed my issue.

With Xcode open:

Open terminal - cd / to your project directory.

Type in: “git reset –hard”

Type in git status

Restart Xcode and make a commit (Just a comment or something )

Repeat the above steps.

This sorted out my issue for me.

3、当你来到这里的时候,你可能遇到上述问题,你必须先移除被追踪的文件,解决方法参考第一种,关闭 Xcode。

  0、在 Git 中,有一个 .gitignore 配置文件,这个隐藏的文件在代码库目录下,其中可以设置被忽略追踪的文件。   

  1、打开终端 cd工程代码库目录vim .gitignore 输入以下命令,退出保存:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Exclue the build directory
build/*

# Exclue temp nibs and swap files
*~.nib
*.swp

# Exclue OS X folder attributes
.DS_Store

# Exclue user-specific Xcode 3 and 5 files
*.mode1
*.mode1v3
*.mode2v3
*.perspectivev3
*.pbxuser
*.xcworkspace

xcuserstate
xcuserdata

  2、如果考虑适用于所有的 Xcode 工程,则需要使用 git config 命令配置 Git,执行命令如下:

1
2
//进行全局配置,并将配置写入~/.gitignore文件
$ git config --global core.excludesfile ~/.gitignore

  3、使本机上的所有代码库都默认使用 Git 用户,执行命令如下:

1
2
$ git config --global user.name userName
$ git config --global user.email userEmail
文章目录
  1. 1. 当 Xcode 遇上 Git,迸发出爱的火花
    1. 1.1. 三种解决方法: