๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Git & GitHub

git diff ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋‘ branch์˜ ์ฐจ์ด์  ํ™•์ธํ•˜๊ธฐ

by ์ฃผ๋ฐœ2 2022. 2. 27.
๋ฐ˜์‘ํ˜•

๐Ÿ“Ž git diff branch1..branch2

์•ˆ๋…•ํ•˜์„ธ์š”, ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” git diff ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋‘ ๋ธŒ๋žœ์น˜ ์‚ฌ์ด์—์„œ ์ฐจ์ด์ ์„ ํ™•์ธํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

๐Ÿ’ก ๊ฐœ์š”

๋ณดํ†ต ์ฝ”๋“œ ์ด๋ ฅ์„ ๊ด€๋ฆฌํ•˜๋Š” ๋„๊ตฌ๋กœ git, github(gitlab, bitbucket) ๋“ฑ์„ ์‚ฌ์šฉ์„ ํ•˜๋Š”๋ฐ์š”, 

git-flow ์ „๋žต์„ ์‚ฌ์šฉํ•˜์—ฌ main, develop, feature, hotfix ๋“ฑ์˜ ๋ธŒ๋žœ์น˜๋ฅผ ๊ด€๋ฆฌํ•˜๋‹ค ๋ณด๋ฉด ๋ธŒ๋žœ์น˜ ๊ฐ„ ์ฝ”๋“œ๊ฐ€ ๋™๊ธฐํ™”๊ฐ€ ๋˜์ง€ ์•Š์„ ๊ฒฝ์šฐ๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

 

https://techblog.woowahan.com/2553/

 

๋ณดํ†ต git-flow ์ „๋žต์—์„œ ์‚ฌ์šฉ๋˜๋Š” ๋ธŒ๋žœ์น˜์— ๋Œ€ํ•œ ์ „๋žต์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค

  • main(master) : ์‹ค์ œ ์ƒ์šฉ ํ™˜๊ฒฝ์— ๋ฐ˜์˜ํ•˜๋Š” ๋ธŒ๋žœ์น˜
  • develop : ๋‹ค์Œ ์ถœ์‹œ ๋ฒ„์ „์— ๋Œ€ํ•ด ๊ฐœ๋ฐœํ•˜๋Š” ๋ธŒ๋žœ์น˜
  • feature : ๊ธฐ๋Šฅ์„ ๊ฐœ๋ฐœํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ธŒ๋žœ์น˜
  • hotfix : ์ƒ์šฉ ํ™˜๊ฒฝ์—์„œ ๋ฐœ์ƒํ•œ ๋ฒ„๊ทธ๋ฅผ ์ˆ˜์ •ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ธŒ๋žœ์น˜

ํšŒ์‚ฌ๋งˆ๋‹ค ์กฐ๊ธˆ์”ฉ ์ฐจ์ด์ ์€ ์žˆ์„ ์ˆ˜ ์žˆ์œผ๋‚˜, ๋ณดํ†ต์€ ์œ„์™€ ๋น„์Šทํ•œ ๋งฅ๋ฝ์œผ๋กœ ๊ฐ ๋ธŒ๋žœ์น˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

์œ„ git-flow ์ „๋žต์— ๋”ฐ๋ฅด๋ฉด ์ผ๋ฐ˜์ ์œผ๋กœ ๊ฐœ๋ฐœ์„ ์ง„ํ–‰ํ•œ ํ›„ ์ƒ์šฉ ํ™˜๊ฒฝ์— ๋ฐ˜์˜ํ•˜๊ธฐ ๊นŒ์ง€์˜ ๋ธŒ๋žœ์น˜ ๊ด€๋ฆฌ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

(์ด๋Ÿฌํ•œ ๊ณผ์ •๋„ ํšŒ์‚ฌ๋งˆ๋‹ค ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ^^)

  1. feature ๋ธŒ๋žœ์น˜์—์„œ ๊ธฐ๋Šฅ์„ ๊ฐœ๋ฐœํ•œ ํ›„ develop ๋ธŒ๋žœ์น˜๋กœ PR & Merge
  2. develop ๋ธŒ๋žœ์น˜ -> main(master) ๋ธŒ๋žœ์น˜๋กœ PR & Merge
  3. hotfix -> main ๋ธŒ๋žœ์น˜๋กœ PR & Merge(๊ธด๊ธ‰ํ•˜๊ฒŒ ๋ฒ„๊ทธ๋ฅผ ์ˆ˜์ • ํ•  ๊ฒฝ์šฐ)

์œ„์™€ ๊ฐ™์€ ๊ณผ์ •์—์„œ ์—ฌ๋Ÿฌ ๋ช…์ด ํ˜‘์—…์„ ์ง„ํ–‰ํ•˜๋‹ค ๋ณด๋ฉด develop ๋ธŒ๋žœ์น˜์—๋Š” ๋ฐ˜์˜ํ–ˆ์œผ๋‚˜ main์—๋Š” ๋ฐ˜์˜๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ๋„ ์กด์žฌํ•  ์ˆ˜ ์žˆ๊ณ , hotfix -> main ์œผ๋กœ ๋ฐ˜์˜ํ—€์œผ๋‚˜ main -> develop ๋ธŒ๋žœ์น˜๋กœ ๋ฐ˜์˜๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๋”ฐ๋ผ์„œ git diff ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋‘ ๋ธŒ๋žœ์น˜ ์‚ฌ์ด์—์„œ ์ฐจ์ด์ ์„ ํ™•์ธํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

๐Ÿ’ก git diff ๋ช…๋ น์–ด ์‚ฌ์šฉํ•˜๊ธฐ

ํ˜„์žฌ ์ปค๋ฐ‹ ๋กœ๊ทธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

git log --branches --decorate --graph --oneline

 

 

๋ธŒ๋žœ์น˜์™€ ๋ธŒ๋žœ์น˜ ์‚ฌ์ด์˜ ์ฐจ์ด์ ์„ ํ™•์ธํ•˜๋Š” diff ๋ช…๋ น์–ด๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

// branch 2๋ฅผ ๊ธฐ์ค€์œผ๋กœ branch1์—๋Š” ์—†๊ณ , branch 2์—๋งŒ ์กด์žฌํ•˜๋Š” ๋‚ด์—ญ
git diff branch1..branch2

์•„๋ž˜ ์ฝ”๋“œ๋Š” ์˜ˆ์ œ๋กœ ์‚ดํŽด๋ณผ main, develop, feature/12 ๋ธŒ๋žœ์น˜์™€ ๊ฐ๊ฐ์˜ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.

 

main ๋ธŒ๋žœ์น˜

main branch

public class MainBranch {
    public static void main(String[] args) {
        System.out.println("Common main branch");
    }
}

 

develop ๋ธŒ๋žœ์น˜

develop branch

public class DevelopBranch {
    public static void main(String[] args) {
        System.out.println("Develop Branch");
    }
}

public class MainBranch {
    public static void main(String[] args) {
        System.out.println("-------------------");
        System.out.println("Common main branch");

        System.out.println("This is develop branch");
    }
}

 

feature/12 ๋ธŒ๋žœ์น˜

feature/12 branch

public class FeatureBranch {
    public static void main(String[] args) {
        System.out.println("Feature Branch");
    }
}

public class MainBranch {
    public static void main(String[] args) {
        System.out.println("-------------------");
        System.out.println("Common main branch");

        System.out.println("This is feature branch");
    }
}

 

git diff main..develop

DevelopBranch ํด๋ž˜์Šค์˜ ๊ฒฝ์šฐ main ๋ธŒ๋žœ์น˜์—๋Š” ์กด์žฌํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ „์ฒด๊ฐ€ ์ดˆ๋ก์ƒ‰(+)์œผ๋กœ ๋ณด์ด๊ณ , MainBranch์˜ ๊ฒฝ์šฐ ์ผ๋ถ€ ์ถ”๊ฐ€๋œ ๋ถ€๋ถ„๋งŒ ์ดˆ๋ก์ƒ‰(+)์œผ๋กœ ๋ณด์ด๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

 

git diff develop..main

develop..main ์˜ ๊ฒฝ์šฐ main..develop ์™€๋Š” ๋ฐ˜๋Œ€๋กœ main ๋ธŒ๋žœ์น˜์— ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ฝ”๋“œ๋Š” ๋นจ๊ฐ„์ƒ‰(-)์œผ๋กœ ๋‚˜ํƒ€๋‚˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

 

git diff develop..feature/12

develop..feature/12 ์˜ ๊ฒฝ์šฐ feature/12 ๋ธŒ๋žœ์น˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ DevelopBranch ํด๋ž˜์Šค๋Š” ์กด์žฌํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ๋นจ๊ฐ„์ƒ‰(-) ์œผ๋กœ ๋‚˜ํƒ€๋‚˜๊ณ , FeatureBranch ํด๋ž˜์Šค์˜ ๊ฒฝ์šฐ ์กด์žฌํ•˜๋ฏ€๋กœ ์ดˆ๋ก์ƒ‰(+)์œผ๋กœ ๋‚˜ํƒ€๋‚˜๋ฉฐ, MainBranch์—์„œ๋„ ๋™์ผํ•˜๊ฒŒ ๋‚˜ํƒ€๋‚˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

๐Ÿ’ก ๋งˆ๋ฌด๋ฆฌ

์ด์ƒ์œผ๋กœ git diff ๋ช…๋ น์–ด์— ๋Œ€ํ•ด ๊ฐ„๋žตํžˆ ์‚ดํŽด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

์œ„ ์˜ˆ์ œ๋Š” ๋งค์šฐ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ž‘์„ฑ๋œ ์ฝ”๋“œ์ด๊ธฐ ๋•Œ๋ฌธ์— ๊ตณ์ด ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋”๋ผ๋„ ํ•œ ๋ˆˆ์— ์ฐจ์ด์ ์„ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ์‹ค๋ฌด์—์„œ ์ž‘์„ฑ๋˜๋Š” ์ฝ”๋“œ์˜ ๊ฒฝ์šฐ ์ˆ˜๋ฐฑ~์ˆ˜์ฒœ ๋ผ์ธ์— ์ด๋ฅด๊ธฐ์— ์ฐจ์ด์ ์„ ๋ˆˆ์œผ๋กœ ํ™•์ธํ•˜๊ธฐ์—๋Š” ํž˜๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ๋•Œ ์œ„ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋‘ ๋ธŒ๋žœ์น˜ ์‚ฌ์ด์—์„œ ์ฐจ์ด์ ์„ ๋ณด๋‹ค ์‰ฝ๊ฒŒ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ์„ ๋“ฏ ํ•ฉ๋‹ˆ๋‹ค.

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€