I am a new developer and just starting to ramp up my PR's at work. So I made a PR and before that PR was merged I made another PR. My first PR was finally approved and merged but the second PR doesnt have the changes from the first one. So I am wondering if I merge the second PR without the changes of the first PR will this override my first PR's changes?
That sounds like a bit of a sketchy operation to me. If you're unsure, here's what I suggest.
Suppose your first PR was merged to origin/master and your second PR is on branch pr2. Then I'd do the following:
git checkout master
git pull --rebase origin master
git checkout pr2
git rebase master
Briefly, I'm suggesting you sync your local master branch with upstream, then rebase your pr2 branch on master. This essentially applies the novel commits in master before your novel commits in pr2. At this stage, you'll find out if you get any merge conflicts. If not, you can examine/test your project and decide if merging your PR will be safe.
Related
https://github.com/Decimal458/test.git
When I create a PR(#3,#5,#7) to merge "dev/" into "stage", the PR include old commit.
But create PR(#4,#6,#8) to merge "dev/" into "main", it would not happend.
In the company I work for, those PRs that are merged into the "stage" may contain more commits and even see other people's files in "Files Changed".
I would like to know how to only display my own commits or files when creating a PR that is merged into stage, just like a PR that is merged into main.
Note: I don't have permission to execute merge in the company.
I would like to know how to only display my own commits or files when creating a PR that is merged into stage, just like a PR that is merged into main.
This is all about rebasing --onto: you rebase only your commits on top of the PR target branch, and then force push your feature branch.
That will update the PR, and show only your own commits.
If you were to make a PR from CVG-xxx to develop, you would see commits from CVG-yyy, because your feature branch was initially create from it.
Assuming CVG-yyy is the commit just before your own CVG-xxx branch:
git fetch
git rebase --onto origin/develop CVG-yyy CVG-xxx
git push --force
The result is: only your own commits are on top of origin/develop now.
Your PR (to origin/develop) will only include your commits.
My work flow to contribute to a repo, is
Create a fork of the upstream
Clone the fork to my local
Push changes to my fork
Create a PR to merge my change into upstream
Sometimes while I am working on my change, other devs might commit their changes into the upstream, so I want to do a rebase which will bring my fork up to date. But I have noticed that in the below scenario, Rebase and Merge Commit gave me different response,
The way I tested it is as follow:
I created a fork of the upstream
I cloned my fork to my local using GitHub Desktop, and set current branch to my fork branch
I then made a change in upstream/master branch and committed it
when I clicked "Rebase current branch", it tells me the current branch is up-to-date as below:
when I clicked "Merge into current branch", it detects a change in the upstream:
upstream/master is the branch in the upstream, and muti/master is the branch in my fork.
My question is, why rebase doesn't detect any change, while the merge and commit does?
Note first that if you have access to the upstream repository, you don't have to fork it in order to push a fix branch and initiate a PR (Pull Request).
You can do all that directly in the upstream repository.
Second, the rebase would only work if the current branch has a divergent history from upstream/master.
If the current branch HEAD is an ancestor of upstream/master, the rebase (of the current branch on top of upstream/master) would be a no-op.
But a merge (of upstream/master into the current branch) would not, since from the point of view of the current branch, there is one commit (done in upstream/master) that it does not have.
I'm new to Github and I have a branch that I want to merge with the master. I couldn't merge it via git command line, its very complicated.
I tried to merge it on Github site following below documentation:
Merging a pull request on GitHub
But I got the following message:
There isn’t anything to compare!
Here's the project:
https://github.com/SumayahAlharbi/erecords
What does 4 commits behind master mean?
Update
Please check below pictures:
I thought I did the merging successfully but nothing changes!
What does 4 commits behind master mean?
It means that the master branch has 4 commits which are not present in your branch currently. You need to rebase your branch and then create a New Pull
Request which will be needed to be reviewed and finally approved so
that your branch can be merged with the master.
There isn’t anything to compare!
Check the difference between the master and your branch. Click the Compare icon in Git hub or run this
command from your local branch in Git Bash : git diff --name-only master_branch.
I just checked your repo. The changes of ExportFeature branch are already merged into the master branch, and then the merge is reverted. That's why now if you raise a pull request to merge ExportFeature into master, you would get There isn’t anything to compare!.
See the latest commits on ExportFeature which are already present in the master branch.
The reason you are seeing 4 commits behind master on ExportFeature branch is since the master branch has 4 more commits than the ExportFeature branch. If you see the total commits on ExportFeature branch, it's 7, whereas the total number of commits on the master branch is 11. If you need to do any more changes on the ExportFeature branch, you would need to get the latest changes from the master branch by running the command git pull origin master when your current branch is ExportFeature on your local git terminal.
While merging a feature branch with the master of GitHub, I have the same scenario and workflow as mentioned in the below question :
Merge non-merged feature branch into another feature branch with Git
I have the master branch. Feature branch1 and the development for feature branch1 is already completed, the code needs to be reviewed and branch should be merged.
Meanwhile, a feature branch branch2 gets created and a piece of work for branch2 depends on code developed in branch1. Since the same code needed in branch2, I have merged and committed the changes in the master branch from branch1 once code review is completed.
Now, I am supposed to get the latest code of master branch in branch2 to start my work in branch2. So, I have merged my feature branch2 again from the master branch.
Is this the correct way to do it, or do I need to delete my feature branch2 and create a new branch again?
Also, since my branch2 was merged from master branch after it was created, when I pushed my changes, that merge was maintained as a history of that branch that will ultimately go to the history of my master branch(as a comment if I do Squash and merge), which is fine.
Now, feature branch2 shows conflicts instead of saying automatically merge. Was this due to the branch1 merge done previously? If so, is there any way to get an automatic merge option into the master branch without any need to resolve conflicts. As I am sure I have already merged the changes from my master branch into feature branch2.
I have created one branch (Sprint1) from master and created one branch (JIRA1) from Sprint1 branch. We have did some commit in Sprint1 and also in JIRA1 branch. We thought that we can not complete development of JIRA1 and we need to merge the Sprint1 with master branch. We want to start development new Sprint2 with new branch Sprint2.
What is best practice to handle such scenario? Can i merge JIRA1 after development in sprint2 branch?
As you have mentioned merge in the question, I don't think you would want to rebase.
Instead, you can merge JIRA1 in SPRINT2 anytime you want.It won't be a problem since (Assuming you have merged SPRINT1 into SPRINT2 or SPRINT2 was created based on SPRINT1) the code base for Sprint 1 and Jira1 is same.
The problem would occur if you try to merge sprint 2 into Jira 1. In that case, you can use git rebase for specific commits of sprint 2.
Sure just merge the changes in Sprint1 to master, and rebase the JIRA1 branch onto the Sprint2 branch using rebase --onto
git checkout develop
git merge Sprint1
git checkout -b Sprint2
git checkout JIRA1
git rebase --onto Sprint2 Sprint1 JIRA1
What this will do is figure out the changes in JIRA1 branch since it diverged from Sprint1, and replay the changes on JIRA1 branch as if it were based on Sprint2 to begin with. Makes sense?
Git rebasing reference