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
Related
In gitlab where is the option to check all the changes in a commit w.r.t the previous commit
IN the image where can I get that
You have a couple of options. On that screen, clicking History will let you see all your commits.
You can also use Repository -> Compare to compare branches.
I have seven commits I need to add change IDs to. I see a lot of people say to use interactive git rebase. I'm not familiar with rebasing, and I'm having trouble with the files and functions that I changed the name of reverting back when I try and reword them to add change IDs.
Is there any other way to add change IDs? Or how do I stop my files/functions reverting back when I try and rebase. Once I abort the rebase, they go back to how I had them.
Thanks!
Try the following, and note you will need to
push and [Submit] one commit at a time:
Set the Gerrit Hook to add the Change-ID as you commit (or amend)
Create a new branch for your changes
For each of the changes, starting with the OLDEST, do:
git cherry-pick ...
git commit --amend (this should add a Change-ID - different one each time)
(push the change to Gerrit - however you do that)
In Gerrit - approve and [Submit] this change
In your branch, again, do git pull --rebase
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.