cherry pick 으로 commit 들을 branch 여기 저기에 밀어넣다보니 누락되는 경우가 잦다.

master 에 3 - 4 - 5 - 6 - 7 이렇게 commit 되어 있는데 5에서 branch 된 branch2 에 7 만 커밋되어 있을 때 6을 찾고 싶은 상황이다.

이 때 git log --cherry-pick 명령을 사용하면 된다.

$ git log --left-right --graph --cherry-pick --oneline master...branch2
< 6d7a4c8 master6

6 번 commit 이 누락된 것을 찾아낼 수 있다.

--cherry-pick 이나 --left-only, --right-only 의 의미는 아래와 같다.

--cherry-pick
Omit any commit that introduces the same change as another commit on the “other side” when the set of commits are limited with symmetric difference.For example, if you have two branches, A and B, a usual way to list all commits on only one side of them is with --left-right (see the example below in the description of the --left-right option). However, it shows the commits that were cherry-picked from the other branch (for example, “3rd on b” may be cherry-picked from branch A). With this option, such pairs of commits are excluded from the output.
--left-only
--right-only
List only commits on the respective side of a symmetric difference, i.e. only those which would be marked < resp. > by --left-right.For example, --cherry-pick --right-only A...B omits those commits from B which are in A or are patch-equivalent to a commit in A. In other words, this lists the + commits from git cherry A B. More precisely, --cherry-pick --right-only --no-merges gives the exact list.

--committer= 를 이용해서 자신의 커밋들로 필터할 수도 있다.

--committer=<pattern>
Limit the commits output to ones with author/committer header lines that match the specified pattern (regular expression). With more than one --author=<pattern>, commits whose author matches any of the given patterns are chosen (similarly for multiple --committer=<pattern>).

2 에서 branch 한 branch1은 4 - 5 를 commit 했다. 4 를 cherry-pick 할 때 conflict 이 발생해서 수정해서 commit 한 상황이다. 이 경우에는 별개의 commit 으로 취급되는 것 같다.

$ git log --cherry-pick --graph --left-only master...branch1 --oneline
* 04a157f (master) master7
* 6d7a4c8 master6
* 9f14aec master4
* b40362d master3

누락된 3, 6, 7 뿐 아니라 4도 목록에 보인다.

출처 : https://medium.com/@Drew_Stokes/git-tips-cherry-picking-logs-d64a71559fd

 

Git Tips: Cherry Picking Logs

Show commit diffs between branches

medium.com

참고 : https://git-scm.com/docs/git-log

 

Git - git-log Documentation

If the commit is a merge, and if the pretty-format is not oneline, email or raw, an additional line is inserted before the Author: line. This line begins with "Merge: " and the hashes of ancestral commits are printed, separated by spaces. Note that the lis

git-scm.com

 

728x90

+ Recent posts