今是昨非

今是昨非

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

Add Pod third-party libraries to gitignore.

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, which caused issues with the production build.

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

During debugging in the main project, we made modifications 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 time to build, the content of the Pod library remained unchanged. This was because the Pod library used in the project specified a version, and when updating the separate Pod library project, we only synchronized it to a branch without updating the new tag. As a result, when updating the main project's library again, the content of this library reverted back to the old version.

Ps: In theory, the content placed in the Pod library should not be frequently modified and should be a foundational library or something similar. However, in practical 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, making it 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 follows:


#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, even though all Pods-related content in .gitignore had been removed. So where did the problem lie? I searched online for many answers, but none of them solved the issue.

At this point, I noticed a line 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 went to the root directory and entered open .gitignore, which prompted The file /Users/horizon/.gitignore does not exist. Ah, so there's 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, and exited. At this point, I saw that 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.