development

git에서 커밋을 스쿼시한다는 것은 무엇을 의미합니까?

big-blog 2020. 9. 24. 08:02
반응형

git에서 커밋을 스쿼시한다는 것은 무엇을 의미합니까?


Squashing commits in git은 무엇을 의미합니까? Github에서 커밋을 어떻게 스쿼시합니까?

저는 Git을 처음 접했고 coala-analyzer의 새로운 버그를 할당 해달라고 요청했습니다. 버그를 수정했고 이제 커밋을 스쿼시하라는 요청을 받았습니다. 어떻게하나요?


Git은 작업 디렉토리 (들)의 스냅 샷에 대한 고급 데이터베이스라고 생각할 수 있습니다.

Git의 아주 좋은 기능 중 하나는 커밋 기록을 다시 작성할 수 있다는 것입니다.
이렇게하는 주된 이유는 그러한 기록의 상당수가 그것을 생성 한 개발자에게만 해당되므로 공유 저장소에 제출하기 전에 단순화하거나 더 멋지게 만들어야하기 때문입니다.

커밋을 스 쿼싱 한다는 것은 관용적 관점에서 해당 커밋에 도입 된 변경 사항을 부모로 이동하여 두 개 (또는 그 이상) 대신 하나의 커밋으로 끝나는 것을 의미합니다.
이 프로세스를 여러 번 반복하면 n 커밋을 단일 커밋으로 줄일 수 있습니다 .

당신이 커밋 태그에서 작업을 시작하면 시각적으로 시작 , 당신이 원하는

Git은 스 쿼싱을 커밋합니다.

새 커밋의 파란색 음영이 약간 더 어둡다는 것을 알 수 있습니다. 이것은 의도적 인 것입니다.

Git에서 스 쿼싱은 Interactive Rebase 라는 특수한 형태 Rebase를 사용하여 수행됩니다 . 커밋 세트를 브랜치 B 로 리베이스 할 때 단순화하면 원래 조상이 아닌 B 에서 시작하여 커밋이 수행 된 모든 변경 사항을 적용합니다 .

시각적 단서

여기에 이미지 설명 입력

파란색의 다른 음영을 다시 확인하십시오.

대화 형 리베이스를 사용하면 커밋을 리베이스하는 방법을 선택할 수 있습니다. 이 명령을 실행하는 경우 :

 git rebase -i branch

리베이스 할 커밋을 나열하는 파일이 생성됩니다.

 pick ae3...
 pick ef6...
 pick 1e0...
 pick 341...

나는 커밋 이름을하지 못했지만,이 네 사람은에서 커밋되는 것이다 시작머리

The nice thing about this list is that it is editable.
You can omit commits, or you can squash them.
All you have to do is to change the first word to squash.

 pick ae3...
 squash ef6...
 squash 1e0...
 squash 341...

If you close the editor and no merge conflicts are found, you end up with this history:

여기에 이미지 설명 입력

In your case, you don't want to rebase into another branch, but rather into a previous commit.
In order to transform the history as shown in the very first example, you have to run something like

git rebase -i HEAD~4

change the "commands" to squash for all the commits apart from the first one, and then close your editor.


Note about altering history

In Git, commits are never edited. They can be pruned, made not reachable, cloned but not changed.
When you rebase, you are actually creating new commits.
The old ones are not longer reachable by any refs, so are not shown in the history but they are still there!

This is what you actually get for a rebase:

여기에 이미지 설명 입력

If you have already pushed them somewhere, rewriting the history will actually make a branch!


The rebase command has some awesome options available in its --interactive (or -i) mode, and one of the most widely used is the ability to squash commits. What this does is take smaller commits and combine them into larger ones, which could be useful if you’re wrapping up the day’s work or if you just want to package your changes differently. We’re going to go over how you can do this easily.

A word of caution: Only do this on commits that haven’t been pushed an external repository. If others have based work off of the commits that you’re going to delete, plenty of conflicts can occur. Just don’t rewrite your history if it’s been shared with others.

So let’s say you’ve just made a few small commits, and you want to make one larger commit out of them. Our repository’s history currently looks like this:

여기에 이미지 설명 입력

The last 4 commits would be much happier if they were wrapped up together, so let’s do just that through interactive rebasing:

$ git rebase -i HEAD~4

pick 01d1124 Adding license
pick 6340aaa Moving license into its own file
pick ebfd367 Jekyll has become self-aware.
pick 30e0ccb Changed the tagline in the binary, too.

# Rebase 60709da..30e0ccb onto 60709da
#
# Commands:
#  p, pick = use commit
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

So, a few things have happened here. First of all, I told Git that I wanted to rebase using the last four commits from where the HEAD is with HEAD~4. Git has now put me into an editor with the above text in it, and a little explanation of what can be done. You have plenty of options available to you from this screen, but right now we’re just going to squash everything into one commit. So, changing the first four lines of the file to this will do the trick:

pick 01d1124 Adding license
squash 6340aaa Moving license into its own file
squash ebfd367 Jekyll has become self-aware.
squash 30e0ccb Changed the tagline in the binary, too.

Basically this tells Git to combine all four commits into the the first commit in the list. Once this is done and saved, another editor pops up with the following:

# This is a combination of 4 commits.
# The first commit's message is:
Adding license

# This is the 2nd commit message:

Moving license into its own file

# This is the 3rd commit message:

Jekyll has become self-aware.

# This is the 4th commit message:

Changed the tagline in the binary, too.

    # Please enter the commit message for your changes. Lines starting
    # with '#' will be ignored, and an empty message aborts the commit.
    # Explicit paths specified without -i nor -o; assuming --only paths...
    # Not currently on any branch.
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #   new file:   LICENSE
    #   modified:   README.textile
    #   modified:   Rakefile
    #   modified:   bin/jekyll
    #

Since we’re combining so many commits, Git allows you to modify the new commit’s message based on the rest of the commits involved in the process. Edit the message as you see fit, then save and quit. Once that’s done, your commits have been successfully squashed!

Created commit 0fc4eea: Creating license file, and making jekyll self-aware.
 4 files changed, 27 insertions(+), 30 deletions(-)
  create mode 100644 LICENSE
    Successfully rebased and updated refs/heads/master.

And if we look at the history again… 여기에 이미지 설명 입력

So, this has been a relatively painless so far. If you run into conflicts during the rebase, they’re usually quite easy to resolve and Git leads you through as much as possible. The basics of this is fix the conflict in question, git add the file, and then git rebase --continue will resume the process. Of course, doing a git rebase --abort will bring you back to your previous state if you want. If for some reason you’ve lost a commit in the rebase, you can use the reflog to get it back.

Details can be found this link.


여러 커밋을 하나로 결합하는 것을 의미합니다. 보세요 :

https://ariejan.net/2011/07/05/git-squash-your-latests-commits-into-one/

Git을 사용하여 마지막 X 커밋을 함께 스쿼시

참고 URL : https://stackoverflow.com/questions/35703556/what-does-it-mean-to-squash-commits-in-git

반응형