Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

smartgit delete commit and return to previous commit

By mistake i have made a commit that now i want to delete from the history log and return to a previous commit. I have been trying to checkout the commit that i want to return to but Smartgit ask me to create a local branch in order to do this (screen shot attached) and since im not an expert with SG i really need some advice. I have also try to revert the commit that i made by mistake but i still see the commit on the log. This is how the log look now:

When trying to checkout :

enter image description here

How my log looks at the moment :

enter image description here

What i want to do is delete the first two commits from the log and return to the "Cambios Varios" commit (the one with the green arrow that btw appeared when i was trying to check out that commit).

All this mess was because my coleague made some changes and add a file and then commit his changes, in order to have my files updated i made a pull but my files didn't get updated on my local repository and didnt add the file that was added by my coleague. Is there something else i have to do in order to update all my folders when another user do a commit besides PULL ? Im pretty new to SmartGit and is kinda of confusing everytime im trying to do a clean pull. Many thanks !

like image 770
Lowtrux Avatar asked Sep 04 '15 09:09

Lowtrux


People also ask

How do you discard changes in git and go back to previous commit?

Try Git checkout --<file> to discard uncommitted changes to a file. Git reset --hard is for when you want to discard all uncommitted changes. Use Git reset --hard <commit id> to point the repo to a previous commit.

How do I revert a commit in SmartGit?

In SmartGit, there are several places from which you can initiate a Revert: Menu and toolbar On the main window, select Branch|Revert to open the Revert dialog, where you can select one or more commits to revert. Depending on your toolbar settings, you can also open this dialog via the Revert button on the toolbar.

How do you go back to previous commit and come back?

Go back to the selected commit on your local environmentUse git checkout & the ID (in the same way you would checkout a branch) to go back: $ git checkout <commit-id> .

How do you remove a commit without losing changes?

Removing the last commit If you want to "uncommit" the commits, but keep the changes around for reworking, remove the "--hard": git reset HEAD^ which will evict the commits from the branch and from the index, but leave the working tree around.


2 Answers

What you are asking is not specific to SmartGit, but to GIT in general. SmartGit is merely a client, though very convenient and fully featured. In your situation you have to take into account several GIT features:

  1. Branches
  2. Published commits
  3. Detached head
  4. Rewriting remote history

Google on these to get additional info. Now, let's give names to your commits:

enter image description here

You continue to see commit A, because you have a branch pointing on it. This is your local branch master. You can reset this branch to whatever commit you like. In SmartGit to do this, just click down on that green branch label and drag it to any other commit. That's it. E.g. reset it to commit B, where origin/master is pointing to, and you will no longer see this commit in your log, because there is no branch from which it can be reached.

Strictly speaking, you may do the same trick with your origin/master branch, you may reset it to any other commit. But you should be very careful with it, because it points on a commit B, which is published. I.e. anyone may have it pulled on their machine. If you cannot tell for sure, you cannot reset branch from a published commit without danger of breaking someone's copy of the repo.

So the simple answer is you cannot revert the repo to the commit C as you want, because it may conflict with repos cloned on other machines. The longer answer is you can try it.

If you are sure that the only persons that have this repo cloned is you and your colleague, you may rewrite the remote log. For this, reset your local master branch on commit C (with drag&drop, as I told earlier) and push it. SmartGit may forbid you from doing so, go to Preferences/Commands/Push and enable option "Allow modifying pushed commits". Because it is dangerous.

This will rewrite position of remote master branch, pull from it from machine of your colleague. If he did not made any additional changes to this branch, this should be fine.

like image 61
Mikhail Avatar answered Sep 22 '22 03:09

Mikhail


TLDR: Here is a screenshot of itsmatgit screenshot

like image 39
David Dehghan Avatar answered Sep 19 '22 03:09

David Dehghan