(Reformatted for the usual inline reply mode [1].) On Fri, Nov 17, 2023 at 02:09:11AM -0800, 凯夏 wrote:
[...] >>> how can i merge test1 test2 into feature1? >>> e94e3c2 feature2 >>> f509e6e test4 >>> 9972849 test3 >>> d7f2f97 feature1 >>> 04ea2a1 test2 >>> 1c0f590 test1 >>> a777378 init >> >> Before we continue... Is this just a list of assorted commits with no >> inherent ordering between them or is there a result of running `git log`? >> >> If it's the latter, feature2 appears to contain both test1 and test2 >> already. >> >> Oops, I wanted to say that feature1 appears to contain both test1 and >> test2, of course. > This is result of running git log. > My bad, the result i want is git log output like this: > yyyyyyy feature2 > xxxxxxx feature1 > a777378 init > xxxxx and yyyyy means this can change. > i just want to delete some unneeded commit to save space. > because test1 maybe change 123 to 124 and test2 maybe change 124 to 125, > and feature1 maybe change 125 to 126, after merge,feature1 can just chang > 123 to 126. Do I understand correctly that you basically want the three changes introduced, sequencitally by the three commits e94e3c2 feature2 f509e6e test4 9972849 test3 to become a single commit (with the message "feature2"), and to do the same with the group d7f2f97 feature1 04ea2a1 test2 1c0f590 test1 to produce a single commit (with the message "feature1")? That would indeed produce yyyyyyy feature2 xxxxxxx feature1 a777378 init as you have indicated. If yes, what you're after is called "squashing", which can be done during so-called "rebasing". Basically, you need to do the following: Run git rebase -i a777378 to start an interactive (hence "-i") rebase of the current tip commit and whatever follows onto a777378. Git will pop out an editor with the so-called "rebase script". It will read something like pick 1c0f590 test1 pick 04ea2a1 test2 pick d7f2f97 feature1 pick 9972849 test3 pick f509e6e test4 pick e94e3c2 feature2 (Note the order reversed compared to that produced by `git log`.) You then change the verbs of the script to read pick 1c0f590 test1 squash 04ea2a1 test2 squash d7f2f97 feature1 pick 9972849 test3 squash f509e6e test4 squash e94e3c2 feature2 The modified script is meant to produce two commits by literally taking a base commit for each group ("pick") and then "squash" the following two commits into it. You save the text and quit the editor, and the rebasing starts. It will stop twice - offering you to provide a commit message for each of the commits to be created. You delete all the offered text to keep only those of "feature1" and "feature2", respectively. After finishing each commit you run git rebase --continue until it says that it has done everything. Verify the result in the usual way (`git log`, `git show`, `gitk` etc). See [2] for more info. [1]: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style [2]: https://git-scm.com/book/en/v2/Git-Branching-Rebasing -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/git-users/20231117122622.pefpq3arjsorhth6%40carbon.