Sourcetree - undo unpushed commits - version-control

I am using Sourcetree for Windows for a git-repository and would like to undo an unpushed commit.
Is that possible? If I do "revert commit", it creates a second commit which reverts the first commit, but I don't want the first commit to appear at all in my source control.
I could also delete my local repository and pull it again without my local commit, but maybe there's another way?

Right click on the commit you like to reset to (not the one you like to delete!)
Select "Reset master to this commit"
Select "Soft" reset.
A soft reset will keep your local changes.
Source: https://answers.atlassian.com/questions/153791/how-should-i-remove-push-commit-from-sourcetree
Edit
About git revert: This command creates a new commit which will undo other commits. E.g. if you have a commit which adds a new file, git revert could be used to make a commit which will delete the new file.
About applying a soft reset: Assume you have the commits A to E (A---B---C---D---E) and you like to delete the last commit (E). Then you can do a soft reset to commit D. With a soft reset commit E will be deleted from git but the local changes will be kept. There are more examples in the git reset documentation.

If you select the log entry to which you want to revert to then you can click on "Reset to this commit". Only use this option if you didn't push the reverse commit changes. If you're worried about losing the changes then you can use the soft mode which will leave a set of uncommitted changes (what you just changed). Using the mixed resets the working copy but keeps those changes, and a hard will just get rid of the changes entirely. Here's some screenshots:

If you want to delete a commit you can do it as part of an interactive rebase.
But do it with caution, so you don't end up messing up your repo.
In Sourcetree:
Right click a commit that's older than the one you want to delete, and choose "Rebase children of xxxx interactively...". The one you click will be your "base" and you can make changes to every commit made after that one.
In the new window, select the commit you want gone, and press the "Delete"-button at the bottom, or right click the commit and click "Delete commit".
List item
Click "OK" (or "Cancel" if you want to abort).
Check out this Atlassian blog post for more on interactive rebasing in Sourcetree.

If You are on another branch, You need first "check to this commit" for commit you want to delete, and only then "reset current branch to this commit" choosing previous wright commit, will work.

Related

How to delete commits from local repository in eclipse?

I have 3 commits staging in the local repo in eclipse that I want to update on github. The problem is that in the first one of these commits I have 2 files overcoming the size of 100 mb so they are not able to be updated.
How can I delete these 3 commits without deleting changes in progress.
To make sure we don't break anything, I would recommend creating a backup of the directory containing your local Git repository.
Then
Commit your "changes in progress"
Go to the "History" view
Right click the commit before the 3 conmmits which you want to remove
Select "Rebase Interactive", the "Rebase Interactive" view will be shown
Select the 3 commits and choose "Skip" as Action
Press "Start" and cross your fingers that you don't have any conflicts
Maybe choose only one file in step 5 if you have conflicts. You can cancel the Rebase by clicking the button "Abort" and make another try.

How to delete any commit from commits table in Gitlab?

In this image you can see list of commit, I want to delete one of them, but I could not find the delete option.
To revert(the right nomenclature) a commit directly on Gitlab it all you need to do is:
Enter the commit you want to revert by clicking on its name;
Click on the button Options;
Click Revert.
Note that similar to reverting a Merge Request, you can opt to revert the changes directly into the target branch or create a new Merge Request to revert the changes.
You can follow the official documentation for more details: https://docs.gitlab.com/ee/user/project/merge_requests/revert_changes.html#reverting-a-commit

Source tree not able to push

So I make my file changes, but when I try to push them source tree complains that some one else pushed before me.The files are different,yet I am forced to merge the changes. Some times I have to backup and reset my workspace before it can allow me to push again
Is there no way to force the push?
Open SourceTree Preferences
Tab: Advanced
Third checkbox: Allow force push
Enable the checkbox and close Preferences.
Next time you push, there will be an extra checkbox: Force push.
Checking it will also display an additional Confirm Force Push dialog box before the force push is actually performed.
Even though the files are different, you have to perform a merge or a rebase before you can push. The commits from your current working branch have to be merged into the current branch that exists on the server before you can update it. You're merging the branches, not the files.
Using the "force push" command does not force your commits to be applied in addition to what is on the remote branch - it forces your commits to replace the commits on the remote branch. Using this option would throw away all of the commits that had been made by the other user.
Because this is a destructive operation, SourceTree does not include GUI access to the "force push" command. Here's what Steve Streeting from Atlassian says about it:
SourceTree doesn't expose force push because it's almost always not what you want to do.
It means that someone else has pushed before you. What you should be doing is pulling their changes, merging them (or rebasing your changes on top of them), and then pushing.

Using modify->reword for commit change in EGit/Eclipse and what to do next?

I have a coworker who is working on a branch called GL104. He made two commits and pushed those to the repository. The newest commit is faed3fd7 on the repos. He then realized he wanted to change his commit message, so he pulled it up in History, right-clicked on the newest commit and selected Modify->Reword. He changed his text and this gave him a new commit ID. He did not do a "Push Commit" or push of any kind to the server. His "status" for the project then showed him being ahead by 2 commits. I suggested he push his local branch up to the repos but it was rejected for non-fast-forward. After that his status showed him being ahead by 1 commit, behind by 1 commit. I don't understand why this is.
Anyway, I'm trying to find this on the net as I type but not finding anything yet. So what is the proper procedure here? I'm guessing he has to push his reworded commit. I'm not sure.
We are using Eclipse Mars.1
Once you push a commit, you normally cannot change the commit message. That is because behind the scenes, when you select "Reword" a new commit is created with the same parent as the old commit. When you have two commits with the same parent, a merge is required; that is why it is not letting you push the new commit.
Now, if nobody else has done a pull on the misworded commit, you can do a force push (git push -f) which will get rid of that commit and replace it with the correct one. But if anyone else has already pulled that misworded commit to their local repo, the force push will simply delay the merging from happening (i.e. when that other person does the next pull).
So, long story short, your coworker is probably best off just leaving the commit as is.

How can I do the equivalent of git rebase -i HEAD~2 in eGit?

I know how to rebase onto a specific branch or tag using eGit in Eclipse, but I haven't found a way to rebase onto a specific sha1 using eGit. I'd like to do this in order to squash commits before pushing to upstream (ie, doing git rebase -i HEAD~n where n is some number of commits ago where I want to rebase). Is this possible with eGit? If not, is there another Eclipse plugin I should be using that would provide this functionality?
EGit has rebase, but it does not yet have the interactive rebase you ask for.
I've been successful squashing commits using steps from this post (cut and pasted here):
If I want to squash the last m commits on the current branch then I
select in history the first commit which I don't want to squash
right-click and say "Team->Reset->Soft"
right-click and say "Commit". This commit will contain all the changes of the last m commits together
It is currently available in Eclipse Oxygen, it has it's own wizard for it.
Get the branch you want in the History view
Right-click the commit before the one you want to change
Find Rebase interactive and click it
The Rebase wizard will show up with the commits available to work upon
It works just like the console version, but on a GUI. Even if conflicts arise, it will help you through.
From the history view select the commit you want to rebase to, and create a branch called rebase-point or whatever. Voila, you can now rebase to that branch, and delete it later if you want. I generally prefer using a named branch for things like this anyway, because it minimizes the chance for mistakes on my part. Alternately, consider that origin/master is often the right rebase point if you're squashing commits for a push.
You can also rebase from the Eclipse History view.
Select the repository from the Git Repositories view
Right-click and select Show In History
Select the commit you want to rebase the currently checked out branch on top of
Right-click and select the Rebase on Top of item
Note: You may need to select Show All Branches and Tags first from the History view toolbar to display the commit you are looking for in the table.