I'm creating a workflow for locked, older branches whereby a select few developers must approve changes made by the team. I plan to limit branch permissions & merge via pull requests (e.g. developer copies the old branch to a new branch, commits on the new branch, issues a pull request to merge the new & old branches and deletes the new branch). My change showed up correctly, but so did a whole lot more:
After the pull request was merged, the commit tab showed many more commits than the one I did. They all look to be those that already existed on the old branch. 14 JIRA issues were also associated with the merge as their IDs were referenced in the old commits. What just happened?
Some investigation reveals:
My conclusion is Stash treated this as two independent branches and completely merged them together. How should I structure this so it doesn't happen on production? I suspect it must have something to do with how I create the new branch...
Thanks for any help!
This is how Git works. An ASCII graph that might help:
o----o----o----o A \---o----o B \---o C
So in this case what would you consider branch C? Obviously if you are merging to branch A then there are going to be two more commits after you merge. What happens if you then merge B? There will only be one new commit because the previous commit was part of the merge with C. If you look at branch B or C in Stash on the commit list we are going to show you every commit, going back in time, which will be 4 commits instead of 1 or 2. The important thing to realise is that Git doesn't label/associate branches with previous commits, it's just a pointer to the most recent commit. How many commits are on branch B or C is purely relative to where it is being merged, nothing more.
I hope that helps and that I've understood your problem correctly?
I'm impressed with your ASCII art abilities! :) Here's a screenshot from fisheye of the branch after the merge. I expected the commit history to be what's shown in purple and am trying to figure out how the stuff that's greyed out got there. They came in as part of the merge so perhaps I mis-created the branch originally? Any ideas appreciated.
Yeah something slightly odd has happened. Your first commt on the branch has two parents where the right-hand side shouldn't be there. Without having access to your repository I couldn't say for sure what or how that happened.
My suspicion is that someone merged master into the branch and then rebased after that. Git then 'recreated' the commits that has previously been merged from master. You can see if the author/message of those other commits are identical to commits on master, but have a different hash. If this is the case I would recommend that you warn your users about rebasing, and ideally disable force pushes on your repository in Stash. While rebasing is a great feature of Git, it requires that the user knows what they're doing and is quite easy to get into trouble. An ascii diagram to help. :)
After the merge A B o---o---o---o master | \ \--o-----o branch C D After the rebase A B o---o---o---o master \ o----o----o---o branch A' B' C' D'
In this case A' is the same patch/changes as A, but they are identified with a different unique hash.
This is only a guess, and I would need more information to say with any more certainty. Let me know if that doesn't make sense, of if you see something odd happening on your next merge. Stash certainly isn't doing anything apart from the merge.
Scott, and anyone else reading this. Apologies, I'm not sure what I was thinking when I posted my previous comment. Maybe I just wanted an excuse to write another ascii graph.
When someone created your branch it looks like they then merged with something, which was the right-hand side (grey) section of your screenshot. It's impossible to say why that happened without knowing what those commits are and/or asking someone how they created the branch. It might be that the original branch was created earlier and then when they pulled it merged with the latest from master, which would create something like what you see there. In which case those grey commits would be expected to be normal commits of your branch, broken up by a merge commit.
In any case let me know if it happens again and maybe we could take a closer look at your workflow.
Charles - Thanks for all the help! I'm learning git and trying all sorts of different things. So, I unintentionally caused the "grey" branch. Good news is it's a test repo so no harm done. I've adopted using these steps which makes the merge in Fisheye look as I'd expect. :-) Any comments appreciated.
$ git checkout -b [local_branch] [remotename]/[locked branch] $ git push -u origin “local_branch”
... Some commits...
Create a pull request in Stash. Assuming it gets approved & merged then:
$ git checkout master $ git branch -d [local_branch] $ git push origin --delete [local_branch]
You can also do 'git checkout locked_branch' if the name is the same as local branch (it creates it the first time). Also we have a checkbox in Stash when closing the pull request that deletes the branch which means you don't need that last step (and I always forget otherwise). Finally when you checkout master remember that you're checking out your _local_ version, don't forget to fetch/pull regularly otherwise you might be out of sync with Stash.
Git can be a little daunting in the beginning, but lots of fun once you get your head around it. Some reading material if you're interested:
Months ago, I was walking in a huge grocery store and I went to the toys aisle and found a jigsaw puzzle that was more than 50% off, and I thought "why not? It will be fun and it can be a beautiful f...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events