๐ ๋ฌธ์ ์ํฉ
git push๋ฅผ ํ๋ ค๋ (non-fast-forward)
์๋ฌ ๋ฉ์์ง๊ฐ ๋์๋ค.
์๋์ ๊ฐ์ ๋ฉ์์ง๋ฅผ ๋ดค๋ค๋ฉด ์ด ๊ธ์ ์ ์ฐพ์์๋ค.
"Push was rejected, and update failed with an error"
error: failed to push some refs to [git-repository-url]
hint: Updates were rejected because the tip of your current branch is behind
์ง์ญํ๋ฉด ํ์ฌ ๋น์ ์ ๋ธ๋์น ์ผ๋ถ๊ฐ origin ๋ธ๋์น์ ๋ค์ ์์๋ค๋ ๋ป์ด๋ค.
์์ธํ๊ฒ ๋ถ์ํด๋ณด๊ธฐ ์ํด sourcetree ๋ฅผ ์ดํด๋ดค๋ค.

๐ก ์์ด๋์ด
ํด๊ฒฐ ๋ฐฉ์ 1. push --force โ
์ด์ ํฌ์คํธ์์ ๋ณธ ๊ฒ์ฒ๋ผ ๊ทธ๋ฅ
$ git push --force origin develop
๊ฐ์ ํธ์ฌ๋ก ์ด์ ๋ก๊ทธ๋ฅผ ๋ฎ์ด์จ๋ฒ๋ฆด ์๋ ์์ง๋ง, ๋ค๋ฅธ ํ์๊ณผ ํจ๊ป ์์ ํ ๊ฒฝ์ฐ ์ด๋ฏธ `4d58421`์ ํด๋นํ๋ commit ์ pull ํด์ ์ฌ์ฉํ๊ณ ์์ ๊ฒ์ด๋ฏ๋ก ์ข์ง ๋ชปํ ๋ฐฉ๋ฒ์ด๋ค.
ํด๊ฒฐ ๋ฐฉ์ 2. reset โ
์ด์ ๋ก๊ทธ๋ฅผ ๊ทธ๋๋ก ์ ์งํ๋ฉด์ Fast-forward ํ ์ ์๋ ๋ฐฉ๋ฒ์ด๋ค.
# 1. ๋น ์ ธ๋์จ ๋ถ๊ธฐ ์ด์ ์ปค๋ฐ์ผ๋ก ๋์๊ฐ.
# ์ฌ๊ธฐ์๋ '626719e'
$ git reset --mixed [๋์๊ฐ ์ปค๋ฐ ํด์]
# 2. ํ์ฌ๊น์ง ๋ณ๊ฒฝ๋ด์ฉ ์ ์ฅ
$ git stash save -m "changed commit list"
# 3. ์๊ฒฉ ๋ฆฌํฌ์งํ ๋ฆฌ ๋ด์ฉ ๋น๊ฒจ์ค๊ธฐ
# ์ฌ๊ธฐ์๋ develop
$ git pull origin [remote-branch-name]

# 4. ์์ ์ ์ฅํ๋ ๋ณ๊ฒฝ ๋ก๊ทธ ๋ถ๋ฌ์ค๊ธฐ
$ git stash pop

Merge Conflict ๊ฐ ๋ฐ์ํ README.md ๋ด์ฉ์ ์๋ a411de2 ์์ ์์ ํ๋๋ก ๋ณ๊ฒฝํ๋ค.
# 5. ์ด์ ๋ณ๊ฒฝ๋ด์ฉ ํ๋์ฉ ํ๋์ฉ ์ปค๋ฐ (์ด๋ฏธ commit ํ๋ ๋ด์ฉ)
$ git commit -m [commit-message]
# 6. ํธ์
$ git push -u origin [remote-branch-name]

sourcetree๊ฐ ๋ธ๋์น์ ์ปค๋ฐ ๋ก๊ทธ๋ฅผ ์๊ฐํํด์ ๋ณด์ฌ์ฃผ๊ธฐ ๋๋ฌธ์ ๋ฌธ์ ์์ธ๊ณผ ์ค๋ง๋ฆฌ๋ฅผ ์ก๊ธฐ ์์ํ๋ค.
ํด๊ฒฐ ๋ฐฉ์ 3. Merge
์ด๋ ๋ฐ๋ก ๋ธ๋์น๋ฅผ ๋ถ๋ฆฌํ์ฌ Merge Request (Pull Request) ๋ก ํ๋๋ก ํฉ์น๋ ๋ฐฉ๋ฒ์ด๋ค.
ํ์ฌ ๋ฌธ์ ์ํฉ์์๋ ๋ธ๋์น๊ฐ 1๊ฐ๋ฏ๋ก ๊ตณ์ด ์ด ๋ฐฉ๋ฒ์ ์ธ ํ์๊ฐ ์๋ค๊ณ ํ๋จํ๋ค.
๐ Reference
How to delete a commit in git, local and remote
It has happened to me more than once that I make a commit without verifying the changes I am committing. Time after that I review the commit and I notice that there is something in the commit that doesn’t belong there. In those times what I want to do is
ncona.com
'๊ธฐํ > git' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [git] ์๋ก ๋ค๋ฅธ repository ํฉ์น๊ธฐ (0) | 2022.03.14 |
|---|---|
| [git] ์ด์ commit ๋ก๊ทธ ๋ณ๊ฒฝ (0) | 2022.03.12 |
| [git] Rebase vs Merge request, Pull request (0) | 2021.12.28 |
| [Git] config (0) | 2021.11.11 |
| [Git] Security Vulnerabilities (๋ณด์ ๋ฌธ์ ํด๊ฒฐ) (0) | 2021.05.12 |