3

背景:我有两个分支,master 和 stable,master 上有许多不稳定的提交。我想挑选一些稳定的提交,然后可以git log --merges-only stable..master用来查看剩下的内容。

但是,如果我只是挑选,git 会将它们视为两次提交,因此“git log”命令无济于事。例如,鉴于此:

# create a repo
mkdir cherry
cd cherry
git init

# add a commit on master
touch foo.txt
git add foo.txt
git commit -a -m 'commit 1'

# create a stable branch
git checkout -b stable

# add two more commits to master
git checkout master
touch bar.txt
git add bar.txt
git commit -m 'commit 2'
touch baz.txt
git add baz.txt
git commit -m 'commit 3'

# cherry-pick just one of those commits to stable
git checkout stable
git cherry-pick master

然后,我希望能够看到哪些提交是未来挑选主人的候选者,理想情况下使用git log,但它并没有真正回答我的问题:

> git log stable..master --pretty=oneline --no-merges
01550adab8993ceb1eec7bbc7a0e3de3550d63fc commit 3
8a3ea27aa50c887b603296bb9d4a36ccbfa35311 commit 2

但是,TIL 关于git cherry

>  git cherry stable master
+ 8a3ea27aa50c887b603296bb9d4a36ccbfa35311
- 01550adab8993ceb1eec7bbc7a0e3de3550d63fc

其中以“+”为前缀的条目是未来樱桃采摘的候选者。

4

3 回答 3

3

git cherry命令就是为此目的而设计的。

于 2013-12-07T00:38:27.883 回答
0

I'm not sure if it will help you or not, but you may want to look at my git-missing script. It mimics Bazaar's bzr missing command. It will show you the extra commits you have on your branch, followed by the commits that are missing from the other branch. It takes cherry picks into account.

For example:

$ git missing master
You have 1 extra revisions
--------------------------
0db6b7c Call SetupSource for .zsh files.

You have 1 missing revisions
----------------------------
70f9f42 Add clojure snippets.
于 2013-12-07T03:58:11.460 回答
0

在您挑选了所有您想要的提交之后,尝试针对 master 重新稳定稳定:

git checkout stable
git rebase master
于 2013-12-06T22:47:43.850 回答