I've accidentally did some changes directly on my master branch. How do I safely merge my master back in to my release branch without loosing any changes that were done on either the master (which were done by me) and on the release branch, there were changes done by my colleagues in that branch. Please advise.
Switch to Release branch and merge master.
git checkout release-blah-branch
git merge master
If the changes will merge without collisions you are done.
Related
Azure Devops
Scenario : I have branch dev and master. There is commit in dev branch AS Commit1, Commit2, Commit 3 and Commit4 and all this changes release on dev site. Now I have approval for Commit1 and Commit3 to release on production. So how can I merge only commit1 and commit3 from dev branch to master branch
Important Note: I'm sure you know this but I think it's worth mentioning that you haven't actually tested exactly what you intend to release. You may benefit from having another branch, say release, where you put the stuff you decide to release, and then you can periodically reset dev to master to clean it up. (And if you do this I would consider calling dev something like next like gitworkflows, which is a similar concept.)
Solution 1 (Most General):
Create a new branch from master, cherry-pick the commits you want from dev, and merge this "release" branch into master.
Solution 2 (Works if your dev branch has merge commits for each commit brought into dev, and those commits' parent is master.):
Create a new branch from master, merge in each of the branches for the commits, and merge this "release" branch into master.
Solution 3 (Works if your dev history is linear after master, and if you never intend to bring in commit 2):
Disclaimer: this is more of an academic answer and I likely wouldn't actually use this solution in your scenario...
Create a new branch from master, and then perform 3 merges:
git switch -c release master
git merge Commit1 # take commit1
git merge -s ours Commit2 # merge commit2 but ignore it's changes!
git merge Commit3 # take commit3
# merge release branch into master
git switch master
git merge release
We've just transitioned to a gitlab system. I pulled from master, created a branch, and am ready commit and request a merge. Before I commit, I want to pull changes that happened in the interim.
Question - do I switch back to the main branch to do the pull? Then switch back to the current branch? But if I do that, will it no longer of the the changes from the pull to main? And if I don't switch to the main branch, will I be committing code without the updated code?
No need to switch to master (do they call it main branch now?), just do the following command from your current branch (replace master with main if your repo is post-BLM):
git merge origin/master
On the Github desktop client, I did the following:
switch to master
pull
switch to branch
merge from master
I'm currently working on an assignment where we work on a local repository and push to a remote repository when we are done. We are expected to make use of branches, wherein we make all our commits before merging it into our master branch, so no commits directly to the master branch.
Everything was going fine, but I've come across a problem when I made some commits on a branch, then merged that branch into my master, before going back to the before-mentioned branch to make some more changes, committing them and merging it once again back into my master branch.
My network tree is currently looking like this:
network branch
The problem being the green branch that is branching off at the end with hash 2bbbd0c.
I'm essentially looking to undo that commit completely and simply have my branch merge into my master, so my network branch shows that nothing is branching off.
One idea I have is to use git reset –hard 2b32611 (which is the hash for my latest commit on the branch before merging it into my master):
enter image description here
And then to use git push -f origin 2b32611:cookies-user-tracking to push the commit and the branch, but once again I’m not sure if that’ll work, and I don’t want to mess anything up.
The git reset --hard will indeed reset cookies-user-tracking to the right commit (before merge)
All you need to do then is to force push the branch:
git push -f origin cookies-user-tracking
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
I have master branch of the project. Then I want to add a new feature so I create a new branch called "new_feature", base on master branch. In new_feature branch, everything works fine and I want to delete some files that are no longer useful. But when I switch back to master branch and merge with new_feature branch, these deleted files still exist.
Here is my question: what I have to do to make master branch is exactly the same as the new_feature branch so I can delete new_feature branch.
Thanks in advance!
You need merge new_feature branch to master.
The steps are,
Switch to master branch
Team - Merge, select new_feature branch
Sounds like you forgot to check in the delete. In Eclipse, switch to the feature branch and open the Git Staging view to see changes that are still pending. File deletes get staged automatically, but not committed.
Required sequence is
Delete - commit - push - checkout other branch - merge - commit - push
#Duc Le: You must merge your new_feature branch to your master branch to get all modified file in new_feature branch into master branch.
Maybe something like this you can follow :
Check your branch :
$ git branch
new_feature * (your active branch)
master
Switch to your master branch :
$ git checkout master
Merge your new_feature to master branch without fast-forward mode:
$ git merge --no-ff new_feature
Explanation about merging without fast-forward