Gerrit always updates parent unmerged commit patchset - gerrit

This issue has been puzzling me for quite sometime now, please help.
Two teams have been working on a project developing 2 submodules:
Team 1: Develops submodule 1 and does a commit and raises a gerrit, say, 233421 (which is UNMERGED, in code review)
Team 2: Does cherrypick of submodule 1 with id 233421, and does a commit of submodule 2 and pushes (gerrit id say 233422)
In step2 above, along with creating a new patchset (233422) for submodule 2, it also updates the cherrypicked patchset 233421.
How to force stop to not update cherrypicked patchset and only create a SINGLE new gerrit with submodule 2's changes in it?

First of all, you should not cherry-pick an unmerged change and use it as a base for a new change. If you really want to do that, you can change the Chante-Id of the new commit created after the cherry-pick, so Gerrit will create a new change for it, instead of updating the original one. I don't think this process is the best but it'll solve the issue you're talking about.

Related

How to overwrite my all local changes in XCode repo when I see "Rebase local changes onto upstream changes" message?

I have a Bitbucket repo where the most recent changes are pushed by another developer teammate. His push is more important and I want to make sure my local is same as the latest in the repo. I have not made any changes but still Xcode shows me this warning. I am fine is all my local is overwritten. How do I do it? Should I check the box when I am pulling changes in Xcode from the BitBucket repo? Or do I need to do a git pull from terminal?
If you want to merge another branch into yours, you should always commit your changes first. When conflicts emerge, you just solve them and there you go, you are on the latest commit with your changes preserved.
If, however, you prefer rebase instead of merge - you HAVE to commit your uncommited changes first, then you can rebase on the latest commit from the other developer's branch, the nice thing about rebase is that it keeps the git history cleaner while also leading you trough the conflict solving, because it basically tries to put each commit of yours on top of the commit that you are rebasing onto, so it sort of "guides" you trough resolving conflicts as you have small chunks of code to resolve and then continue rebase.
Try to read more on this. This article summarises the difference between merge and rebase:
https://www.freecodecamp.org/news/an-introduction-to-git-merge-and-rebase-what-they-are-and-how-to-use-them-131b863785f/

Script to build the LAST commit in a Gerrit topic branch

We're using Gerrit. We thought we could do the following:
create some commits on a topic branch:
- a
- b
- c
Push those commits to gerrit.
Get some reviews.
Have Jenkins build only the last commit of the bunch.
Unfortunately, it looks like gerrit internally creates three different branches for those three commits, and when we have Jenkins run the script to build the topic, it winds up picking a different commit than the one we intended. Is there someway to get the behavior we desire?
You can change the project configuration to only create one review for your series of changes. This can be done by setting the Create a new change for every commit not in the target branch to false
Biggest disadvantage is that you can't review what has been changed in the changesets leading up to the latest change.
See the Gerrit Documentation
Gerrit always creates one change (review) for each commit pushed. There's no way to create one unique change for a bunch of commits. Commits are stored in special branches (like, for example, refs/changes/12/40312/1) until they aren't submitted (merged in the final branch).
You can, of course, build several commits at once after they are submitted to the branch but you only can trigger Jenkins to start a build every time some commit is merged in the branch (one build for each commit). If you want to have just one build for a bunch of commits you could consider to make scheduled builds started automatically some time of the day (night builds).

How to add changes when using git

I have a question about git.I'm working in a project and i have 9 branches, the first branch name was make users system.
Today i want to add an avatar to my users but i don't know what is the step to do with git.
Should i create a new branch ?
git checkout -b add-more-details-to-users
Or just switch to my first branch make users system then add changes ?
thank for helps
It all depends on your workflow. If you're working in a team, most of the times when implementing a new feature it's better to create a new branch, test it and merge with the master. It's not a good practice to put too much code and implemented features in one branch since it increases the possibility of breaking up some other functionality.
Also I would suggest you to make your branch names more descriptive, like: add-avatar-to-user , not make-users-system and if you're using any project management tools, task/story id like so: add-avatar-to-user-12345
Take a look at this link, I like this kind of workflow, we are currently using it in our team:
http://scottchacon.com/2011/08/31/github-flow.html
Since it sounds like make users system is like your master branch, you should checkout a new branch from it, which is called a feature branch, add the changes and, when you're happy the changes and everything works, merge it back.
You should really read up on some articles on how to keep your branches organized
http://nvie.com/posts/a-successful-git-branching-model/

Git: How to create a new branch but somewhat different project

I am going to update my Rails3 project to 4 and at the same time have a clean start project all together. So my solution is to create a new rails4 project and just transfer one by one, what I need in my previous project.
I was thinking of creating a new branch for my new rails4 project and eventually when I'm done is transfer it back to master and override it. I have come up with two solutions but I don't know what both implications would be. Which should I implement?
Just create a new branch git checkout -b v2 and do a git rm -rf on the project. Start my new rails app and commit or
Use --orphan? I just recently found this option in git. So I'd use git checkout --orphan v2 do also a git rm -rf on the project and start my new rails app and commit.
Basically they look almost the same but I was wondering like what would happen if I tried to merge them back to master or override master already?
my old project already has a lot of clutter and unused codes and I don't want to do the new one on top of those already. So instead of remove what I don't need, I opted of moving what I need
One solution would simply to manage a different repo, if having the history isn't that important.
Or, if you must keep one repo, go with option 2/ (orphan branch)
If the merge to master with override is what worries you, I have summarized the different ways to achieve that in "git command for making one branch like another".

How can I move my changes to a new branch after the fact?

I was working on my Rails project which is checked into Git. I read tutorials and they said for every time you start to change something, check out a branch.
However, accidentally I made some changes but did not check out a branch.
What should I do now?
What commands can I run so that Git takes my new changes and push them on my repository?
git stash
git checkout $correct_branch
git stash apply
Of course, if your changes are already on the branch you're going to put them on, just commit and go with it.
I hope you added a commit into jkp's answer. I can see somebody running that exact sequence without doing a commit and thus wiping out all their uncommitted changes...
It's not mandatory to make a branch, just best practice. It's perfectly legimate to work against master if you want. If you didn't create an explicit branch then you'll be working against master anyway and can push to that.

Resources