Git: Only merge the last commit of a specific branch to the main branch
Note: this the second part of the wiki which shows how to only push the last commit to a remote: https://yctct.com/git-push-specific-commits-only-remote
You have a bunch of unmerged commits on a branch but only want to merge to the last one to the main branch. To do so, run:
$ git branch # you are on hte branch where you want to pick the last commit from
branch-with-the-commit-you-want-to-merge
$ git last # print the hash of commit you want to merge
7f023b7 last commit # copy the hash to the clipboard
$ git switch main
$ git cherry-pick 7f023b7 # merge commit with hast 7f023b7
Make sure that files of the last commit have not been modified previously on that same branch where you are picking the last commit from. Otherwise, reorder and squash (see https://yctct.com/git-squash).
personal computing command-line interface (cli) gnu linux trisquel shell literacy office applications wiki git