I'm trying to figure out a workflow for a shared repository that multiple people will push to. The goal is to give people the ability to commit locally as often as they want to, retaining information on when they created and merged branches, while keeping a clean history on the branch they eventually push to.
With the man page for git-merge stating that merge
...will replay the changes made on the topic branch since it diverged from master (i.e., E) until its current commit (C) on top of master, and record the result in a new commit...
what I THOUGHT you could do is the following:
- Clone repository, need to change something in branch
master - Create a local branch
branch, do all the work in say 5 commits - Merge the local branch back into
masterwith the--no-ffswitch, forcing the creation of a merge commit (which contains the changes of all merged commits). - Push that merge commit
master
The local history I get when I do this looks like this:
* cada35b - Tue, 26 Feb 2019 08:55:45 +0100 (21 minutes ago) (HEAD -> master, origin/master) | 6 - dev * 8391544 - Tue, 26 Feb 2019 08:55:44 +0100 (21 minutes ago) | 5 - dev * 4381abd - Tue, 26 Feb 2019 08:55:41 +0100 (21 minutes ago) | 4 - dev * 40e21b1 - Tue, 26 Feb 2019 08:54:49 +0100 (22 minutes ago) |\ #3254 Important Feature - Merge branch 'branch' - dev <-- Merge commit | * 4f595e8 - Tue, 26 Feb 2019 08:54:38 +0100 (22 minutes ago) (branch) | | 3.3 - dev | * ea05ba7 - Tue, 26 Feb 2019 08:54:36 +0100 (22 minutes ago) | | 3.2 - dev | * d779583 - Tue, 26 Feb 2019 08:54:34 +0100 (22 minutes ago) |/ 3.1 - dev * fab5a25 - Tue, 26 Feb 2019 08:54:20 +0100 (22 minutes ago) | 3 - dev * b6ddac3 - Tue, 26 Feb 2019 08:54:19 +0100 (23 minutes ago) | 2 - dev * 0abafad - Tue, 26 Feb 2019 08:54:18 +0100 (23 minutes ago) 1 - dev This is correct and what I want. What I would have expected (and need) on the remote is a history that looks like this:
* cada35b - Tue, 26 Feb 2019 08:55:45 +0100 (7 minutes ago) (HEAD -> master, origin/master, origin/HEAD) | 6 - dev * 8391544 - Tue, 26 Feb 2019 08:55:44 +0100 (7 minutes ago) | 5 - dev * 4381abd - Tue, 26 Feb 2019 08:55:41 +0100 (7 minutes ago) | 4 - dev * 40e21b1 - Tue, 26 Feb 2019 08:54:49 +0100 (8 minutes ago) | #3254 Important Feature - Merge branch 'branch' - dev <-- Merge commit * fab5a25 - Tue, 26 Feb 2019 08:54:20 +0100 (9 minutes ago) | 3 - dev * b6ddac3 - Tue, 26 Feb 2019 08:54:19 +0100 (9 minutes ago) | 2 - dev * 0abafad - Tue, 26 Feb 2019 08:54:18 +0100 (9 minutes ago) 1 - dev However, what I actually get is all the commits I made locally, just without the branch pointer for the branch I didn't push:
* cada35b - Tue, 26 Feb 2019 08:55:45 +0100 (7 minutes ago) (HEAD -> master, origin/master, origin/HEAD) | 6 - dev * 8391544 - Tue, 26 Feb 2019 08:55:44 +0100 (7 minutes ago) | 5 - dev * 4381abd - Tue, 26 Feb 2019 08:55:41 +0100 (7 minutes ago) | 4 - dev * 40e21b1 - Tue, 26 Feb 2019 08:54:49 +0100 (8 minutes ago) |\ #3254 Important Feature - Merge branch 'branch' - dev <-- Merge commit | * 4f595e8 - Tue, 26 Feb 2019 08:54:38 +0100 (8 minutes ago) | | 3.3 - dev | * ea05ba7 - Tue, 26 Feb 2019 08:54:36 +0100 (8 minutes ago) | | 3.2 - dev | * d779583 - Tue, 26 Feb 2019 08:54:34 +0100 (8 minutes ago) |/ 3.1 - dev * fab5a25 - Tue, 26 Feb 2019 08:54:20 +0100 (9 minutes ago) | 3 - dev * b6ddac3 - Tue, 26 Feb 2019 08:54:19 +0100 (9 minutes ago) | 2 - dev * 0abafad - Tue, 26 Feb 2019 08:54:18 +0100 (9 minutes ago) 1 - dev Is there any way to only push the merge commit and have it contain all the changes that were made on the local branch? I am aware merge --squash and rebase -i exist, but with those you cannot see at what point something was merged back into a branch (merge --squash) or lose the local history entirely (rebase -i).
git log ...?git log --all --graphexcluding some formatting switches i use (which don't show up here anyway)git merge. That commit creates a merge commit with two parents. If you push your local branch which contains this two-parent-commit, your remote branch will inevitably also get the two-parent-commit. You could, as you mentioned, do ` git merge --squash`, this way, you'll be creating one commit which contains all changes made on the side branch, with only one parent (ie. you will be dropping the history of the side branch. You can choose one of these approaches, but you cannot have one of them on your local branch and the other on the remote branch.