今是昨非

今是昨非

日出江花红胜火,春来江水绿如蓝

gitignore add Pod third-party library

Background#

Recently, our project encountered an issue that took a long time to troubleshoot. Eventually, we discovered that there was a problem with the code of a private component that our Pod dependency relied on, resulting in issues with the production build.

In our project, we abstracted private components based on functionality and imported them using Pod. However, the content of Pods is not committed to git, so any changes made to Pods cannot be seen in the git changes of the main project. This led to the problem we encountered.

During debugging in the main project, we made changes to the content of the Pod library. Then, we synchronized the modified content to the separate project of the Pod library. However, when it came to the final build, the content of the Pod library remained unchanged. This was because the Pod library specified a version in the project's dependencies, and when we updated the separate Pod library project, it was only synchronized to a branch without updating the new tag. As a result, when we updated the main project's library again, the content of this library reverted to the old version.

Ps: In theory, the content placed in the Pod library should not be frequently modified and should be a basic library or similar. However, in actual development, for the purpose of componentization, some functional components may also be used as private libraries with Pod dependencies, and these libraries may undergo frequent changes.

Based on this, I felt that it would be better to include the content of Pods in the main project's .git file, as it would be easier to see the modifications and avoid the aforementioned problem.

Modification#

I directly entered the directory where the project is located and edited the .gitignore file, removing the content related to #CocoaPods, as shown below:


#CocoaPods
Pods/
Pods
.DS_Store
Podfile.lock
/.DS_Store
Podfile.lock
/Podfile.lock

Changed to:


#CocoaPods
.DS_Store
/.DS_Store

After saving and exiting, I found that the Pod library still did not appear in git, and all Pods-related content in .gitignore had been removed. So where did the problem occur? I searched online for many answers, but none of them solved the issue.

At this point, I noticed a sentence at the top of .gitignore:

# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

I searched for Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore but did not find any similar files. Then I thought, could there be a global .gitignore file? So I entered the root directory and typed open .gitignore, which prompted The file /Users/horizon/.gitignore does not exist. Ah, so there is no such file? I then entered ls -a and discovered that the file in the root directory was actually named .gitignore_global. After opening it, I found that it did indeed have Pods set in it. I deleted it, saved it, and exited. At this point, the files in Pods appeared in the main project's .git.

Conclusion#

After editing the .gitignore file in the project, if you find that it is not taking effect, you can go to the root directory and open .gitignore_global to see if this global configuration also needs to be modified.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.