How to delete commit history in gerrit in eclipse? - eclipse

I have done some incorrect commits using gerrit in eclipse. Now, I want to delete my commit history.
*Doing hard reset to the original head i.e. before any commit does not work.

Open command prompt or git bash.
git revert HEAD~1..HEAD
It will checkout the previous commit. It will get you in to a state called detached head. create new branch from this point and continue your work,
if the commit is a merge add -m flag
git revert -m HEAD~1..HEAD

Related

How to undo the most recent comment on git

While using git hub I wanted to delete/undo a comment that I had recently posted. But I was unable to do it. So I want to know how to undo the recent comment in git.
Here is one of the several and easiest way to do it.
First of all lets check commit history.
git log --oneline
Now in the output you will see a list of commits. Something like shown below.
241b8e7 (HEAD -> papers) Added paper-logic according to new requirements
8ae8f7d paper backend fixed
3c9a3ce toggle sidebar change added
af1af34 link to style tag added
Now as per your question you want to undo previous commit i.e you want your project to be at 2nd last commit.
So "code"(left of commit statement- "paper backend fixed" ) for 2nd last commit from the above example is 8ae8f7d. Copy this code.
To go to that commit enter the following in terminal.
git reset --hard <code>
What this will do is forcefully change all your project to the stage as it was on mentioned commit.
Note that it is irreversible i.e once you have gone to previous commit you cannot come to commits above it
You need to undo the commit as well.
Undo Last Git Commit with reset
$ git reset --soft HEAD~1
If you are not familiar with this notation, “HEAD~1”
“HEAD~1” means that you want to reset the HEAD (the last commit) to one commit before in the log history.
You can use this as well
$ git reset --hard <commit sha1 | reference>
$ git push --force
to check the commit hash and reference you can use
$ git log --oneline
or
$ git log
Undo Last Git Commit with revert
$ git log
$ git revert <commit sha1 | reference>
$ git push --force
You might want to check these as well
How do I undo the most recent local commits in Git?

Git revert and reset : Files in the repository are not getting rolled back

I want my entire repository to roll back to a certain previous commit (that is 20 commits behind my latest commit).
I tried using git reset --hard <commit#> and git revert <commit#>
Both the git commands run successfully with the message - Head is now at <commithead>
But then when I see the code in my repo, I can still see the edits I made in my latest commits. How can I remove all the edits after the particular commit I am reverting to?
Am I missing out on some step here?
After your git reset --hard, use to be sure the git restore command
cd /path/to/repository
git restore -- .
That should restore (as its name implies) the working tree with what is in HEAD (and you just reset HEAD to the right commit)

How to revert a pull request commit on GitHub

I am trying to revert my latest commit on GitHub. All the information I have looked through says that there should be a revert button in the pull request but I do not see it, and cannot find it.
Is there anyway to do this on GitHub? Or could I do it terminal with a few rebase commands?
Assuming this pull request merge is a commit merge (what I would expect), then you may try the following from the Git bash:
git checkout your_branch
git revert <hash of merge commit> -m 1
git push origin your_branch
This solution assumes that you want to revert back to the branch into which the pull request merge was made. If you want to follow the incoming branch, then use -m 2 instead.
To find the SHA-1 hash of the merge commit, you may use git log, and then copy over the hash from the first commit, which should appear at the top.
Note that nuking the merge commit and then doing a force push is generally a bad idea here. The reason it is bad is because your branch is published on GitHub. This means that rewriting the history of that branch could cause problems for anyone besides you who happens to be sharing this branch.
In android studio click version control tab in the bottom. Then click log
Then your all the commits will be visible. Then right click on relvent commit and revert it.
Then commit changes and push again.
Get the hash of the commit in which you want to revert back. Then do:
git checkout 54722c31619b0662b379923d0be4b8f8f1f125c9
The long number you are seeing is the hash of that particular commit in which you want to revert back.
Then force push into the branch you want to revert back.
git push origin <your_branch_name> --force
I hope this helps. Happy coding :)

committed without git pull, not pushed due to conflict

I am using netbeans to pull/commit/push to git. I have accidentally make commit before pull request and now it's asking me Rebase/Merge. Either of option gives me error. I tried with following links using Windows git shell
How to undo last commit(s) in Git?
How to revert Git repository to a previous commit?
How to undo last commit
Remove a git commit which has not pushed
I have tried following commands:
git checkout <commit sha key>
git reset --hard <commit sha key>
NOTE: I have commited change but not pushed!
try git reset --soft HEAD~1
when you haven't pushed yet, a soft reset will take all the changes from the latest commit, and place them back onto stage again. in other words, the status of your repo will look exactly as it was the moment before you commited.

Revert central SVN repo from git-svn

Basically, I would like to revert a central SVN repository back to a previous commit, kinda like this:
svn update
svn merge -r 150:140 .
svn commit -m "Rolled back to r140"
But I'm using git-svn and cannot seem to find an equivalent.
I've tried setting everything up locally on a new branch by checking out an earlier commit that was an ancestor of trunk (the current commit of the central repo). I made a few additional changes and now I cannot git svn rebase or git svn dcommit without getting an error from SVN.
I tried checking out that same commit without making the additional changes and then running git svn dcommit, this says it is committing to the central repo but doesn't actually seem to do anything.
How do I go back to a previous commit and then start making new changes?
Your task is essentially to reset your git HEAD into the state of r140, but in a way that would allow a straightforward git svn dcommit.
One way of doing this:
# checkout git revision of the desired state
git svn find-rev r140 | xargs git checkout
# reset HEAD to the revision 150, assuming it was the latest svn commit in trunk
git reset trunk
git add -u
git commit -m "Rolled back to r140"
git svn dcommit
You could also take a look on thread Revert multiple git commits