[Swift] XCode Project File (.xcodeproj, .pbxproj) & Conflict์— ๋Œ€ํ•˜์—ฌ

2023. 1. 27. 15:03ใ†Programming/Swift

 

 

Xcode Project

An Xcode project is a repository for all the files, resources, and information required to build one or more software products. A project contains all the elements used to build your products and maintains the relationships between those elements. It contains one or more targets, which specify how to build products.
A project defines default build settings for all the targets in the project (each target can also specify its own build settings, which override the project build settings).

 

 

 

An Xcode project file contains the following information:

  • References to source files:
    • Source code, including header files and implementation files
    • Libraries and frameworks, internal and external
    • Resource files
    • Image files
    • Interface Builder (nib) files
  • Groups used to organize the source files in the structure navigator (๊ณ„์ธต์œผ๋กœ ๋ณด์ด๋Š” ํด๋”๋“ค(๊ทธ๋ฃน)๋„ ํฌํ•จ๋œ๋‹ค)
  • Project-level build configurations. You can specify more than one build configuration for a project;
    for example, you might have debug and release build settings for a project. 
  • Targets, where each target specifies:
    • A reference to one product built by the project
    • References to the source files needed to build that product
    • The build configurations that can be used to build that product, including dependencies on other targets and other settings; the project-level build settings are used when the targets’ build configurations do not override them 
  • The executable environments(์‹คํ–‰ ํ™˜๊ฒฝ) that can be used to debug or test the program, where each executable environment specifies:
    • What executable to launch when you run or debug from Xcode
    • Command-line arguments to be passed to the executable, if any
    • Environmental variables to be set when the program runs, if any

A project can stand alone or can be included in a workspace.

You use Xcode schemes to specify which target, build configuration, and executable configuration is active at a given time.

 

 

 

  • Project๋Š” Application์„ ๋นŒ๋“œํ•˜๊ธฐ ์œ„ํ•œ ํŒŒ์ผ, ๋ฆฌ์†Œ์Šค, ์ •๋ณด๋ฅผ ๋‹ด์€ repository
  • ์ฒ˜์Œ Xcode๋ฅผ ์ผœ๊ณ  Single View Application์„ ์ƒ์„ฑํ•˜๋ฉด Project๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด๋•Œ, ํ”„๋กœ์ ํŠธ์˜ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์‚ดํŽด๋ณด๊ฒŒ ๋˜๋ฉด ํ”„๋กœ์ ํŠธ๋ช….xcodeproj๋ผ๋Š” ํŒŒ์ผ์ด ์ƒ๊ธด ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์ •ํ™•ํžˆ ์–˜๊ธฐํ•˜๋ฉด ์ด๋Š” ํŒŒ์ผ์ด ์•„๋‹ˆ๋ผ ๋””๋ ‰ํ† ๋ฆฌ์ž…๋‹ˆ๋‹ค.
    ํ„ฐ๋ฏธ๋„์„ ํ†ตํ•ด ํ•ด๋‹น ํŒŒ์ผ๋กœ ๋“ค์–ด๊ฐ€๊ฒŒ ๋˜๋ฉด project.pbxproj์ด๋ผ๋Š” ํŒŒ์ผ๊ณผ xcuserdata๋ผ๋Š” ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

 

  • project.pbxproj๊ฐ€ ์‹ค์ œ ์„ค์ • ํŒŒ์ผ์ด๋‹ค. 
  • ํ”„๋กœ์ ํŠธ ๋‚ด๋ถ€์—์„œ ์ƒ์„ฑ๋œ ํŒŒ์ผ์„, ํŒŒ์ผ ์œ ํ˜•์— ๋”ฐ๋ผ reference๋ฅผ ์ €์žฅํ•˜๋Š” ์—ญํ• 
  • .xcodeproj : ํŒŒ์ผ์ด ์•„๋‹Œ ๋””๋ ‰ํ† ๋ฆฌ์ž„์„ ์ฃผ์˜!
     ํ•ด๋‹น ๋””๋ ‰ํ† ๋ฆฌ์— project.pbxproj ํŒŒ์ผ, project.xcworkspace ํŒŒ์ผ,  xcuserdata ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์กด์žฌ

 

  • ์ด project.pbxproj๋Š” ์‚ฌ์‹ค git์„ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ์ถฉ๋Œ์ด ์ผ์–ด๋‚˜๋Š” ์ฃผ์š” ํŒŒ์ผ ์ค‘ ํ•˜๋‚˜!
  • xcode์˜ ์ตœ์ƒ์œ„ ํ”„๋กœ์ ํŠธ ๊ด€๋ฆฌ ํŒจํ‚ค์ง€์ธ .pbxproj์˜ ๊ฒฝ์šฐ git ๋ณ‘ํ•ฉ์‹œ ์–ด๋–ป๊ฒŒ ๋ณ‘ํ•ฉํ•  ๊ฒƒ์ธ๊ฐ€์— ๋Œ€ํ•ด ๋‚œ๊ฐํ•œ ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์Œ
  • 2๋ช…์˜ ํŒ€์›์ด ์ž‘์—…์„ ์œ„ํ•ด ๊ฐ์ž A ํŒŒ์ผ, B ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜์—ฌ ๊ฐ์ž ์ปค๋ฐ‹ํ•œ ๊ฒฝ์šฐ ํ•œ ์ชฝ์—๋Š” B ํŒŒ์ผ์˜ reference, ๋‹ค๋ฅธ ์ชฝ์€ A ํŒŒ์ผ์˜ reference๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ๋‘ ์ž‘์—…์—์„œ ์‚ฌ์šฉ๋œ project.pbxproj ํŒŒ์ผ์€ ์„œ๋กœ ๋‹ค๋ฅธ reference๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์„œ conflict๊ฐ€ ์ผ์–ด๋‚ฉ๋‹ˆ๋‹ค.
    ๊ทธ๋ฆฌ๊ณ  ์ด ์ถฉ๋Œ์ด ๊ณ ์น˜๊ธฐ ์‰ฝ์ง€ ์•Š์€ ๊ฒƒ์ด project.pbxproj๊ฐ€ ๊นจ์ง€๋ฉด ํ”„๋กœ์ ํŠธ ์ž์ฒด๊ฐ€ ์—ด๋ฆฌ์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ ์ด๋Ÿด ๋•Œ๋Š” ์—๋””ํ„ฐ๋‚˜ ์†Œ์ŠคํŠธ๋ฆฌ ๊ฐ™์€ ํ˜•์ƒ ๊ด€๋ฆฌ ํˆด๋กœ ํ•ด๋‹น ์ถฉ๋Œ์„ ์ˆ˜์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. (dev - dev - mybranch)
  • xcuserdata๋Š” ํ”„๋กœ์ ํŠธ์˜ ๊ฐœ์ธ ์„ค์ •์„ ๋‹ด์€ ๋””๋ ‰ํ† ๋ฆฌ: breakpoint, UI layout ์„ค์ • ๋“ฑ์„ ๋‹ด์•„, ํ”„๋กœ์ ํŠธ ์ž์ฒด์— ํฌ๊ฒŒ ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๋Š” ๋””๋ ‰ํ† ๋ฆฌ (.xcuserdata ์ถ”์  ๋ฐฉ์ง€ ์ถ”๊ฐ€ ์„ค์ • ๊ฐ€๋Šฅ)

 

  • Workspace๋Š” ์—ฌ๋Ÿฌ ๊ฐœ์˜ Project๋ฅผ ๋‹ด์•„ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ฃผ๋Š” ๊ฐœ๋…
  • CocoaPod ์‚ฌ์šฉ ์‹œ ์ ‘ํ•˜๊ฒŒ ๋œ ๊ฒฝ์šฐ ๋งŽ๋‹ค. (๋‚˜๋„!)

 

  • Target์€ ํ”„๋กœ์ ํŠธ๋ฅผ ํ†ตํ•ด ์ƒ์„ฑ๋˜๋Š” Application์„ ์ง€์นญํ•จ. ์ผ๋ฐ˜์ ์œผ๋กœ ํ•˜๋‚˜์˜ ๋ชจ๋“ˆ์„ ์˜๋ฏธ
  • Target์€ Xcode์˜ ๋นŒ๋“œ๋ฅผ ํ†ตํ•ด ์ƒ์„ฑ๋œ ์ตœ์ข… product
  • Target์€ ์–ด๋–ป๊ฒŒ ํ”„๋กœ์ ํŠธ๋ฅผ ๋นŒ๋“œํ•  ๊ฒƒ์ธ์ง€๋ฅผ ๋‹ด๋‹น
  • ๊ธฐ๋ณธ์ ์œผ๋กœ Target์€ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ์‹œ 1๊ฐœ๋งŒ ์ƒ์„ฑ๋˜์ง€๋งŒ, ๋ชฉ์ ์— ๋”ฐ๋ผ์„œ ํ•˜๋‚˜์˜ ํ”„๋กœ์ ํŠธ์— ์—ฌ๋Ÿฌ ๊ฐœ์˜ Target์„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Œ
    • ๊ฐ๊ฐ์˜ target์€ ํ”„๋กœ์ ํŠธ์˜ build setting์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.
    • ๊ฐ๊ฐ์˜ target์€ ํ”„๋กœ์ ํŠธ์—์„œ ํฌํ•จ๋  ๊ฐ์ฒด, ๋ฆฌ์†Œ์Šค, ํ˜น์€ ๋ณ„๋„์˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋”ฐ๋กœ ์„ค์ •ํ•˜๋„๋ก ํ•จ
    • Xcode์—์„œ๋Š” target์„ ํ†ตํ•ด์„œ ํ•˜๋‚˜์˜ ํ”„๋กœ์ ํŠธ๋ฅผ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋ฐฐํฌํŒ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•จ
      (i.e. iPhone์šฉ target, iPad์šฉ target, ํŠน์ • ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ํฌํ•จ๋œ target ๋“ฑ)

 

  • Scheme์€ Target์ด ํ”„๋กœ์ ํŠธ๋ฅผ Build, Profile, Test๋“ฑ์„ ํ•  ๋•Œ ์ผ์–ด๋‚  ์ผ๋“ค์„ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ฃผ๋Š” ํ•ญ๋ชฉ
  • Scheme์—์„œ๋Š” ํ”„๋กœ์ ํŠธ ๋นŒ๋“œ์‹œ ์‚ฌ์šฉ๋˜๋Š” ํ™˜๊ฒฝ๋ณ€์ˆ˜๋‚˜ ์ธ์ž๋ฅผ ๋„˜๊ฒจ์ค„ ์ˆ˜ ์žˆ์Œ
  • Scheme์€ ํ”„๋กœ์ ํŠธ์˜ ๋Ÿฐํƒ€์ž„์—์„œ ์ผ์–ด๋‚  ์ผ์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Œ

 

 

 

  • pbxproj is an important file in the Xcode configuration bundle. It is responsible for maintaining references to all of the linked files and their groupings, linked frameworks, and most importantly, the project's build settings
  • pbxproj ํŒŒ์ผ์€ Build Setting(์‹ค์ œ ํ”„๋กœ์ ํŠธ์˜ ์„ค์ •) ์„ ๋‹ด์€ ํŒŒ์ผ
    ํ”„๋กœ์ ํŠธ ๋‚ด๋ถ€์—์„œ ์ƒ์„ฑ๋œ ํŒŒ์ผ๋“ค์„ ํŒŒ์ผ ์œ ํ˜•์— ๋”ฐ๋ผ reference๋ฅผ ์ €์žฅํ•˜๊ณ  ์žˆ์Œ
    conflict๋Š” ํŒŒ์ผ์— ๋Œ€ํ•œ reference๊ฐ€ ์—†์„ ๋•Œ ์ผ์–ด๋‚œ๋‹ค.
  • ์ค‘์š”ํ•œ ํŒŒ์ผ์ด๋ฏ€๋กœ .gitignore์— ์ถ”๊ฐ€ํ•  ์ˆ˜ ์—†๋Š” ํŒŒ์ผ์ด๋‹ค. 
  • pbxproj ํŒŒ์ผ์€ ๋ณด๊ธฐ๊ฐ€ ๋„ˆ๋ฌด ๋ถˆํŽธํ•˜๋‹ค. Pro Git Book ์—์„œ๋Š” ์‚ฌ์‹ค ํ…์ŠคํŠธ ํŒŒ์ผ์ด์ง€๋งŒ ๋งŒ๋“  ๋ชฉ์ ๊ณผ ์˜๋„๋ฅผ ๋ณด๋ฉด ๋ฐ”์ด๋„ˆ๋ฆฌ ํŒŒ์ผ์ด๋ผ๊ณ  ๋งํ•˜๋ฉฐ, ์—ฌ๋Ÿฌ ๋ช…์ด ์ด ํŒŒ์ผ์„ ๋™์‹œ์— ์ˆ˜์ •ํ•˜๊ณ  Merge ํ•  ๋•Œ diff๊ฐ€ ๋„์›€์ด ๋˜์ง€ ์•Š๊ณ  ํ”„๋กœ๊ทธ๋žจ์ด ์ฝ๊ณ  ์“ฐ๋Š” ํŒŒ์ผ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ”์ด๋„ˆ๋ฆฌ ํŒŒ์ผ์ฒ˜๋Ÿผ ์ทจ๊ธ‰ํ•˜๋Š” ๊ฒƒ์ด ์˜ณ๋‹ค๊ณ  ํ•œ๋‹ค. (๋‚˜๋Š” ์ด ํŒŒ์ผ๋กœ conflict ํ•ด๊ฒฐ์„ ์ง์ ‘ ํ–ˆ์—ˆ๋Š”๋ฐ.. ๋‹ค๋ฅธ ๋ฐฉ๋„๋กœ๋Š” pbxproj ํŒŒ์ผ์„ binary ํŒŒ์ผ๋กœ ์ทจ๊ธ‰ํ•˜๊ธฐ ์œ„ํ•ด ํ”„๋กœ์ ํŠธ ์ตœ์ƒ์œ„ ํด๋”(README.md๊ฐ€ ์žˆ๋Š” ๊ณณ)์—์„œ .gitattributes ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด, conflict ๋ฐœ์ƒ์„ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•œ๋‹ค.)

 

 

 

  • ์ด๋ฒˆ ํ”„๋กœ์ ํŠธ์—์„œ ํŒŒ์ผ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ ์ด์œ  (๋นจ๊ฐ„ ๊ธ€์”จ ๋œจ๋Š” ์˜ค๋ฅ˜ -> ์ข…์ข… ๋ฐœ์ƒํ•œ๋‹ค)
    • ์ถ”๊ฐ€๋œ ํŒŒ์ผ์— ๋Œ€ํ•˜์—ฌ project file์„ ํ†ตํ•œ reference๊ฐ€ ์ œ๋Œ€๋กœ ๋”ฐ๋ผ์˜ค์ง€ ์•Š์•„์„œ
    • ๋กœ์ปฌ์—๋Š” ์ œ๋Œ€๋กœ ๋“ค์–ด๊ฐ€ ์žˆ๋Š” ํŒŒ์ผ๋“ค์„, ์ง์ ‘ ์žฌ์—ฐ๊ฒฐํ•ด์ฃผ๋ฉด ํ•ด๊ฒฐ๋œ๋‹ค
    • + build Phase์—์„œ .gitkeep ์ง€์šฐ๊ธฐ
  • ํŒŒ์ผ์— ๋Œ€ํ•œ ์ฐธ์กฐ๋Š” xcodeproj/project.pbxproj ํŒŒ์ผ์— ์ €์žฅํ•˜๊ณ  ์žˆ๋‹ค. 
    ๋”ฐ๋ผ์„œ, ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ์‚ญ์ œํ•œ ๊ฒฝ์šฐ project.pbxproj๋„ ํ•จ๊ป˜ ์ปค๋ฐ‹ํ•ด์ค˜์•ผ ํ•œ๋‹ค.
  • ํ”„๋กœ์ ํŠธ ํŒŒ์ผ๋“ค์˜ ๋ณ€๊ฒฝ์ ์„ ํ™•์ธํ•œ ๋’ค, ํ•จ๊ป˜ ์ปค๋ฐ‹ํ•ด์ฃผ๊ธฐ! :)

 

 

 

Xcode์— ํŒŒ์ผ ์ถ”๊ฐ€ํ•˜๊ธฐ

1. Destination

- Copy items if needed

ํŒŒ์ผ์„ ๋ณต์‚ฌํ•˜์—ฌ ์ถ”๊ฐ€ํ•˜๋Š” ์˜ต์…˜ - ์ฒดํฌํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค. (Copy by Value๊ฐ™์€ ๊ฐœ๋…)

์ด ์˜ต์…˜ ์—†์ด ์ถ”๊ฐ€ํ•œ๋‹ค๋ฉด ํ”„๋กœ์ ํŠธ ํด๋”๋กœ ๋ณต์‚ฌ๋˜์ง€ ์•Š๊ณ  ์›๋ณธ์˜ ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ์ฐธ์กฐ -> ์›๋ณธ์˜ ํด๋”๊ฐ€ ๋ณ€๊ฒฝ๋˜๊ฑฐ๋‚˜ ์‚ญ์ œ๋  ๋•Œ ๋” ์ด์ƒ ํ•ด๋‹น ํŒŒ์ผ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๊ฒŒ ๋œ๋‹ค.

+ ๋‚ด project.pbxproj ํŒŒ์ผ์—๋Š” ๋ฐ˜์˜์ด ๋˜์–ด ์žˆ์ง€๋งŒ ์ด๋Œ€๋กœ git์— ์ปค๋ฐ‹ํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด, ๋‹ค๋ฅธ ์‚ฌ๋žŒ๋“ค์—๊ฒŒ๋Š” ํ•ด๋‹น ํŒŒ์ผ์ด ์กด์žฌํ•˜์ง€ ์•Š์•„ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

2. Added folders

- ํŒŒ์ผ ์ถ”๊ฐ€

ํ•ด๋‹น ์˜ต์…˜์€ 'Added folders' ์˜ต์…˜์œผ๋กœ, ํŒŒ์ผ ์ถ”๊ฐ€์— ๋Œ€ํ•ด์„œ๋Š” ๋‘ ์˜ต์…˜์— ๋Œ€ํ•œ ์ฐจ์ด๊ฐ€ ์—†๋‹ค. 

 

- ํด๋” ์ถ”๊ฐ€

1) Create groups

  • ๋…ธ๋ž€ ํด๋”๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค.
  • ๊ฐ€์ƒ ํด๋”์˜ ๊ฐœ๋…์œผ๋กœ ํŒŒ์ผ ์‹œ์Šคํ…œ(Finder)์„ ์˜๋ฏธํ•˜์ง€ ์•Š๋Š”๋‹ค.
  • Finder์—์„œ ํด๋” ๋‚ด์— ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•ด๋„ ํ”„๋กœ์ ํŠธ ํด๋” ๋‚ด์—๋Š” ๋ฐ˜์˜๋˜์ง€ ์•Š๋Š”๋‹ค.
  • Finder์—์„œ ํด๋”์˜ ์ด๋ฆ„์„ ๋ณ€๊ฒฝํ•ด๋„ ํ”„๋กœ์ ํŠธ ๋‚ด์—์„œ ํด๋”๊ฐ€ ๋‚จ์•„ ์žˆ๋‹ค. (๋‚ด๋ถ€ ํŒŒ์ผ์€ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค.)
  • Finder์—์„œ ํด๋”๋ฅผ ์‚ญ์ œํ•ด๋„ ํ”„๋กœ์ ํŠธ ๋‚ด์— ํด๋”๋Š” ๋‚จ์•„ ์žˆ๋‹ค. (๋‚ด๋ถ€ ํŒŒ์ผ์€ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค.)

2) Create folder references

  • ํŒŒ๋ž€ ํด๋”๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค.
  • ํŒŒ์ผ ์‹œ์Šคํ…œ(Finder)์˜ ํด๋”์— ์ผ๋Œ€์ผ ๋งตํ•‘๋œ๋‹ค. ๋”ฐ๋ผ์„œ, ๋ณ€๊ฒฝ ๋‚ด์—ญ์ด ๋ฐ˜์˜๋œ๋‹ค.
  • Finder์—์„œ ํด๋” ๋‚ด์— ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•˜๋ฉด ํ”„๋กœ์ ํŠธ ํด๋” ๋‚ด์—๋„ ํŒŒ์ผ์ด ์ถ”๊ฐ€๋œ๋‹ค.
  • Finder์—์„œ ํด๋”์˜ ์ด๋ฆ„์„ ๋ณ€๊ฒฝํ•˜๋ฉด ํ”„๋กœ์ ํŠธ ๋‚ด์—์„œ ํด๋”๊ฐ€ ์‚ญ์ œ๋œ๋‹ค.
  • Finder์—์„œ ํด๋”๋ฅผ ์‚ญ์ œํ•˜๋ฉด ํ”„๋กœ์ ํŠธ ๋‚ด์—์„œ๋„ ํด๋”๊ฐ€ ์‚ญ์ œ๋œ๋‹ค.
  • ๋‚˜๋Š” ์ฃผ๋กœ ํŒŒ๋ž€ ํด๋”๋กœ ์‚ฌ์šฉํ–ˆ์—ˆ๋‹ค.

 

 

 

Xcode์—์„œ ํŒŒ์ผ ์‚ญ์ œํ•˜๊ธฐ

- Remove Reference

ํŒŒ์ผ์— ๋Œ€ํ•œ ์ฐธ์กฐ๋งŒ ์ œ๊ฑฐ๋œ๋‹ค. ๋”ฐ๋ผ์„œ ํŒŒ์ผ ์ถ”๊ฐ€ ์‹œ Copy items if needed ์˜ต์…˜์„ ์„ ํƒํ•˜์ง€ ์•Š์•˜๋‹ค๋ฉด, ์ฐธ์กฐ๋งŒ ์ œ๊ฑฐํ•˜์—ฌ๋„ ์ƒ๊ด€์—†๋‹ค.

๋งŒ์•ฝ Copy items if needed ์˜ต์…˜์„ ์„ ํƒํ•˜์—ฌ ์ถ”๊ฐ€ํ–ˆ๋Š”๋ฐ, Remove Reference๋กœ ์ œ๊ฑฐํ•œ๋‹ค๋ฉด ์‹ค์ œ ํ”„๋กœ์ ํŠธ ํด๋”์— ํŒŒ์ผ์€ ๋‚จ์•„์žˆ์ง€๋งŒ, ์ฐธ์กฐ๋งŒ ์ œ๊ฑฐ๊ฐ€ ๋œ ์ƒํƒœ์ด๋‹ค. ๋‚จ์€ ํŒŒ์ผ์€ Finder์—์„œ ์ง์ ‘ ์‚ญ์ œํ•  ์ˆ˜ ์žˆ๋‹ค.

 

- Move to Trash

ํŒŒ์ผ์— ๋Œ€ํ•œ ์ฐธ์กฐ์™€ ํ•จ๊ป˜ Finder์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌผ๋ฆฌ์ ์ธ ํŒŒ์ผ๊นŒ์ง€ ํ•จ๊ป˜ ์ œ๊ฑฐ๋œ๋‹ค.

 

 

 

Understand why merge conflicts happen

Version control systems, like git, auto-magically manage code contributions. It identifies the change, when it occurred, who made it, and on what line so that developers can easily track the history of their codebase.
However, git sometimes gets confused in the following situations:

  • When more than one person changes the same line in a file and tries to merge the change to the same branch
  • When a developer deletes a file, but another developer edits it, and they both try to merge their changes to the same branch.
  • When a developer deletes a line, but another developer edits it, and they both try to merge their changes to the same branch
  • When a developer is cherry-picking a commit, which is the act of picking a commit from a branch and applying it to another
  • When a developer is rebasing a branch, which is the process of moving a sequence of commits to a base commit

Git is unsure which change to apply, so it leans on the developer for help and notifies them of a merge conflict. Your job is to help git determine which proposed change is most accurate and up to date.

 

 

 

The benefits of preventing merge conflicts

Sometimes, doing that upfront work for your team or yourself to avoid merge conflicts may seem tedious, but it's worthwhile. Using guard rails to prevent merge conflicts will save time and increase developer happiness. Solving a bug, writing a new feature, or scripting automation is time-consuming. Adding the barrier of debugging and resolving a merge conflict means it takes longer to merge to 'main' and longer to deploy to production. Also, if your team is constantly experiencing conflicts, they'll eventually feel disenchanted with their work.

 

Four ways to prevent merge conflicts
  1. Standardize formatting rules.
  2. Make small commits and frequently review pull requests.
  3. Rebase, rebase, rebase (early and often)
  4. Pay attention and communicate.

 

 

 

โœณ๏ธ Four ways to prevent merge conflicts

Standardize formatting rules

Many times conflicts occur because of formatting discrepancies. For example, a technologist inadvertently added extra white space on the same line where another developer added new code. Also, people have different coding styles. For instance, some JavaScript developers use semicolons, but some don't. If you're working on a team, enforce code formatters and linting rules. Make sure everyone on the team is aware of these rules and tools to reduce the number of merge conflicts you experience due to formatting.

Make small commits and frequently review pull requests

I'm going to admit something super embarrassing. Back in the day (~3 years ago), I would make pull requests changing over 50 files, and then I would get annoyed that I had so many merge conflicts. (์™€์šฐ) In hindsight, I was wrong. Changing over 50 files in less than two weeks increased the chances that other developers also made updates to those files.

Also, creating large pull requests discouraged my teammates from thoroughly and quickly reviewing my code. My pull request would sit longer than necessary because it was a behemoth my teammates preferred to avoid.

Take my mistakes as a lesson to make small changes, commit them, and have folks review the pull request as soon as they are available. This way, you'll have fewer chances to change files that other teammates are simultaneously working on. 

Rebase, rebase, rebase (early and often)

I learned about rebasing in 2019 from a coworker that my team dubbed the "Git-tator" (Git and dictator combined). He was earnest about improving our startup's git history and reducing the number of blockers we experienced due to merge conflicts. Arguments ensued because many developers were often working on extensive features simultaneously. We even argued over simple conflicts when people imported new dependencies for different features in the same file on the same line. Thus, he introduced us to rebasing, which significantly improved our software development workflow.

What is rebasing?

The git rebase command reapplies changes from one branch into another, which is very similar to the git merge command. However, in this case, git rebase rewrites the commit history to produce a straight, linear succession of commits.

How rebasing helps prevent merge conflicts

Rebasing is not going to magically remove all merge conflicts. In fact, you may encounter conflicts while rebasing. Sometimes, you will have to repeatedly resolve the same conflict while rebasing. However, merge conflicts happen because multiple changes happen to the same chunk of code simultaneously. If you rebase your local working branch with the default branch (main or master), you're rewriting your local commit history with the default branch's history and then reapplying your changes. In many situations, rebasing first and then merging can make teamwork easier. Rebasing is an option, but not the only solution.(dev-dev-my branch๋ž‘ ๋‹ค๋ฅธ๊ฑธ๊นŒ? ๋ญ์ง€?) 

Be careful with rebasing

Be warned – there are moments when rebasing is not recommended. Rebasing is dangerous because you're rewriting history. When rebasing, pay attention to the changes you're accepting because you risk overwriting teammates' changes or including files your teammates intended to delete. You also probably wouldn't want to rebase a public repository on the main branch because that would inaccurately rewrite the history.

If you're new to rebasing or nervous about rebasing, pair with a teammate to sanity check.

How I rebase to avoid merge conflicts

There's no correct workflow – just preferred ones.
Here's the workflow I follow as determined by teams and codebases I’ve worked in:

  • If I'm working with more than one person, I'll create a feature branch from the default branch.
    This way, we can contribute to the feature branch in tandem.
  • I'll make a new local branch from the default or feature branch
  • I'll add and commit new changes to my local branch
  • I'll rebase updates from the default or feature branch
  • I'll merge changes from my local branch to the default or feature branch

Pay attention and communicate

No git command or software tool can replace the need for communication in engineering teams. Being a good software developer and collaborator goes beyond writing code. Good software developers communicate with teammates. Keep your team aware of what files you will be touching and coordinate with your Product Manager and SCRUM Master to avoid working on features that conflict with other features. 

If you're working alone, pretend you're working on a team by:

  • creating branches 
  • creating pull requests
  • Avoid allowing pull requests to become stale
  • Make sure you're not changing the same lines of code before merging a prior change
  • Establish and follow formatting rules 

Working alone shouldn't stop you from practicing healthy coding habits, so try to keep your codebase clean!
Your codebase may turn into an open source project or a project that you show off in interviews.

 

 

 

 

 

 

 

์ถœ์ฒ˜

 

 

 

 

'Programming > Swift' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Swift] RXSwift Refactoring in iOS  (0) 2024.02.13
[Swift] Alamofire vs Moya & URLSession์— ๋Œ€ํ•˜์—ฌ  (0) 2023.01.27
[Swift] SnapKit vs AutoLayout & Pros and cons of using 3rd-Party  (0) 2023.01.26
[Swift] CocoaPod vs Swift Package Manager  (0) 2023.01.26
[Swift] tap gesture  (0) 2022.11.21