I committed like 10 individual cherry-picked changes to my new release branch, and now after regression testing found that one of those commits in the middle may have broken something. I am prepared to release a new version of the code but exclude that commit. Must I start over cherry-picking into the new release branch to do this right, or is there a way I can simply copy my current branch into a new release branch and revert or undo the single offending commit without losing those that came before or after it?
I ended up creating a new release branch and starting over, cherry-picking into the new release branch the individual commits that I wanted and skipping the one I didn't want.
There is also another method I learned but didn't use--which is,
git revert <commit-hash>
However, while it does undo a commit in the branch where it exists so that the resulting code is devoid of that commit's changes, git revert does create a new revert-related commit in the git log for that branch to undo the unwanted commit--so it's not really a clean, make-like-it-never-happened erasure because you'll still see it in the branch's history.
Related
I got conflicts When I try to rebase feature_branch with develop in android studio. When I resolve those conflicts again another set of files comes up with conflicts. This is happening because feature_branch has many commits.
Can someone suggest to rebase feature_branch to develop in this case?
Git accomplishes rebase by creating new commits and applying them to the specified base. The branch is composed of entirely new commits.
You can minimize the new commits by running git rebase with the -i flag. Instead of blindly moving all of the commits to the new base, interactive rebasing gives you the opportunity to alter individual commits in the process. This lets you clean up history by removing, splitting, and altering an existing series of a commit.
https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase
First step to do before rebasing is to squash all commits to one final new commit. you can do this using git rebase -i HEAD~N where N is the number of commits you have in the current branch.
After this, you can easily rebase with a develop branch with easy conflicts.
This method may lose the commit history of the current branch as we are squashing all commits to one. If you want to save the history of the current branch then create new branch from the current branch before doing rebase as mentioned in the first point.
I have pushed a commit by mistake to my Gitlab. How can I undo it?
Easy way is to click the revert button in the merged merge request.
Click for Reference docs
Steps to revert a merge request from UI:
Click revert button
This creates a new branch rever-some_sha.2
Either opt for a new merge request and submit that.
[ Or ]
Checkout to revert-some_sha locally, add any changes you wanted.
Create a merge request and click merge to master.
Recommendation: Do a periodical rebase of your branch to be on top of master. Which avoids any conflicts and helps to catch any failing tests before even merging your branch.
I quote rednaw:
You can revert commits with git revert . This will create
a new commit which reverts the changes of the commit you specified
with the .
Note that you only revert that specific commit, and not commits after
that. If you want to revert a range of commits, you can do it like
this:
git revert <oldest_commit_hash>..<latest_commit_hash>
Just note that this command is a little bit funny. It actually doesn't
revert the commit specified with itself, but the
commits after that until and including .
Look at the git-revert man page for more information about the git
revert command. Also look at this answer for more information about
reverting commits.
Note that this revert command also deletes the corresponding local
files
Assuming that you mistakenly created a merge request on Gitlab,
All you have to do is scroll to the bottom of the merge request page and click on the
button close merge request
When I need to save my changes from one branch before checking out to another branch, git sometimes says: stage or commit the files before you can checkout to another branch. But I have been recommended to use stash option so:
Stage the files is not enough to save my files before checking out to another branch?
What are the differences between stage and stash files?
Thanks
1.- More than "save" your files, is act as Git expect to according their flow. (Advice, Git knows :) )
2.- Stash will move your modified files into a stack. So, later in the same or in another branch, you will be able to bring them back and see those modifications in your project.
Stage is the step before to make a commit, you add modified files to "Staged files" to create your next commit.
Now, you stash your files with
$git stash
and you add files (stage) with
$git add
Now, why is better stash your changes than staging them?
Maybe this part of the documentation can solve your doubts:
From documentation:
Stashing:
Often, when you’ve been working on part of your project, things are in
a messy state and you want to switch branches for a bit to work on
something else. The problem is, you don’t want to do a commit of
half-done work just so you can get back to this point later. The
answer to this issue is the git stash command.
See the links below :
Git Stashing Doc
Git Add Doc
Staging example
Git Basics
It's better to ask difference between stash vs commit and not stash vs stage.
You can not checkout to another branch before commit or stash current changes.
Therefore, if you want to not commit your changes, and also want to checkout to another branch, solution is to stash current changes, checkout to another branch. And after returning to first branch, you can apply stashed changes.
I had a functional version of code which I was trying to commit to my local branch,
However, previously I tried to make some changes that were not accepted on that branch. So I reverted back to a previous commit.
So I was working out of a commit that was 2nd to last in the branch
Then I made some more changes, tested the program, and tried to commit again,
Then tortoise svn forced me to update, I assumed it was updating the files for the current revision I was on. But no, unfortunately, it Updated the files to the Latest commit, which I did not want, then it tried to merge my changes on top of that, so I had changes that I wanted on top of changes that I didn't want merged together!
Can I undo this and keep my changes that I just made that I wanted to commit? What did I forget to do, was I supposed to stash all of the newer commits?
Right click on file you will have option replace with choose the local history. Select the local version you want to keep.
Its done. You are good to go :)
we cut branch from Trunk. Changes are done on both trees and committed. Now we want to merge branch to trunk with all the revision history from both. Is it possible?
Is manual merge is different from tortoise SVN merge say i have to do 3-4 files?
"Means i manually check the changes then do it on trunk and commit the trunk."
I earlier put a question regarding it but still confused.
Experts comment only.
Thx
You should be able to merge from your branch to trunk by simply right clicking on the target branch and selecting merge. Typically, a reintegrate merge will merge all changes from a branch back into the target branch. I have had failures with that in the past based on the version of svn, how merges have been done in the past, etc. At that point, I simply would do a 'Merge revision range' without specifying a revision. It then picked up the appropriate ranges to merge and successfully pulled those over to trunk.
Once the merge is done, you must commit the merges. Simply put, the merge operation completes on your local working copy. You will then have to commit the changes to your working copy in order for others to pick it up. I recommend doing merges on clean copies of branches/targets (meaning you have no outstanding changes on either branch). Also, make sure you commit any property changes as well.
Lastly, if you just want to merge a specific change, you can specify the revision in which the change was made instead of doing a full merge/reintegration.