How do I revert back to earlier commit using source tree - xcode

I have a project stored on my Mac and created a repository for from that location to my project. I am able to commit using source tree but now I would like to revert back to an earlier commit so all my files in folder update? I'm not sure how i do this?

Temporary Revert Back
If you want to temporarily go back to this commit, then come back to where you are.
Right click on the commit you want to revert to and click on "checkout".
Permanent Revert Back
This will add commits to revert all your work since this commit
Right click on the commit you want to revert to and click on "Reset <> to this commit".

I think in above discussion #dominones and #Giraldi maybe misunderstand each other,
#Giraldi maybe want to delete those unwanted commits permanently in the GIT, and make the git go back to a certain history commit, from there he could start all over again, like you want to be fresh from the beginning of somewhere.
while #dmonones is showing just how to revert back to a status of your code in a history, discarding some code changes you did, which will mostly end up with a new commit aiming to remove a unwanted/mistaken change,
without changing the git history.
To discard an already committed commit in git history, you need to use hard reset and push with force.

Related

Have i lost my changes after using Revert?

I made some changes to a few files within VS 2019.
I added a comment and clicked Commit All under Git Changes tab (didnt do a Push).
I realised i made a mistake by including some temp files so i clicked Revert under Git Repository Explorer against the comment i made.
All my changes have been lost in VS 2019..... Is there anyway to recover my changes?
Managed to resolve this after panicking a bit!! Just in case this helps anyone
Clicked Git in the VS 2019 menu.
View Branch History.
Under Local History, i right clicked the row where i made the changes and added my comment.
Selected Revert > accepted the warning
All my work was restored. I then continued to do the usual Commit and Push which then pushed my changes to the repo and i was able to verify that.

Undo a specific file revert in TortoiseGit

In TortoiseGit commit dialog (before making a commit), I selected a particular file and right click -> Revert
I have changed my mind and would like to "unrevert" this file.
I can't find anything that achieves this. There is no record in the log of this specific file revert and of course because I hadn't committed those changes there is no point to roll back to. Is this possible?
The file should be put into the Windows recycle bin before the changes were undone.
There is no other failsafe active, as the changes were not version controlled (committed).
Also see https://tortoisegit.org/docs/tortoisegit/tgit-dug-revert.html

Do I need to Create New Branch in Git if I am must rolling back changes?

I Commited (call it Original). Then I made a bunch of changes.
Now I want to just roll them all back.
So I'm doing a Switch/Checkout. But I'm wondering if (and why) I need to Create New Branch (the default option).
First: Dropping commits means that you want to change the history. This might be problematic if you work with other people on a common repository and you already pushed your changes. - Either you do this rollback as described in the following text and force push (then you collaborators need to adjust their local history manually after pulling) or you revert the commits (option revert change by this commit) and push these changes (the revert is a normal commit which reverts the changes and will be automatically applied to your collaborators on pull).
If you really want to roll back all changes, the fastest way to go is to perform a "hard reset" to the revision you want to go back to (then the history and all files in the working tree are rolled back to the state of that revision, the other commits will be discarded as if those never happened).
If you want to keep one or more commits in the history, you should go for a rebase operation. Select the commit in the log dialog which should be the base for the "new" history and select "rebase onto this revision". Then flag all commits you want to drop as skip and perform the rebase.
cf. https://tortoisegit.org/docs/tortoisegit/tgit-dug-showlog.html#tgit-dug-showlog-actions and https://tortoisegit.org/docs/tortoisegit/tgit-dug-rebase.html
(Your itend to performa a "Switch" sounds like you have a SVN background; switch/checkout in Git means in generall that you want to switch to an existing branch or create a new branch).
see the documentation ...in that GUI it's called revert change by this commit:
Revert changes from which were made in the selected revision. All changes are integrated into your working tree. You may choose to commit immediately or edit and commit later. To abandon the reverted changes, perform a hard reset.

xcode source control doesn't show current branch

I'm using the standard xcode source control (version 9.3)
I just reopened my project and when I go to the Source Control Navigator:
It shows a long hex string at the top instead of the current branch name
None of the branches have '(current)' next to them
I have tried cleaning the project and also closing and re-opening.
Source Control->Commit brings up the standard commit interface with the option to leave a comment.
When I click on the very top row (with blue icon) I can see the new commits but they don't show in any of the branches.
What am I doing wrong?
This worked for me:
I clicked on the row with the long hex name. This brought up the version history for the current version.
I right-clicked the most recent change in the change history.
I clicked 'Branch from...' and created a new branch from that point.
For those wondering how something like this could have happened, it is caused when you checkout a commit rather than checkout a branch. Even if you checkout a commit inside the branch that is "current" (even the most recent commit), this will cause the branch to no longer have the "current" written next to it. So when you are sure that this previous commit that you have now checked out is the commit you want to work with, then you must do what Derek posted to do which is to "Branch from..." to make a temporary branch and then merge this temporary branch into the branch that this previous commit originally came from. And then you can delete the temporary branch. It is somewhat of a pain, but a good reason why Xcode does this is so that you are well aware that you are on a previous commit and that you should really make sure this previous commit is what you want your current branch to be at.

How to ignore uncommited change in Github gui for MAC?

I am using Github GUI for Mac.
Now I've some changes in my local repository, but I want to ignore them and pull latest remote repository.
I tried Repository/Pull, but got Git Error.
"•error: Your local changes to the following files would be overwritten by merge:
Classes/xxx.m
Please, commit your changes or stash them before you can merge."
I tried Repository/Synchronize, but got following error.
"Sync Failed. Please commit all your changes before syncing."
Any idea?
Place a checkmark near each of the changed files, then go to the Repository menu and click Discard Changes to Selected Files.
If you mean using MAC GUI only, check and right click the changed files then select the discard the changes.
if you want to remove your uncommitted changes, just do a checkout on those files again.
Stash is super easy too though, and it keeps your changes in a local 'bucket' or stash :)
For those on Github for Windows, it is not obvious where Discard All Changes is, so I wanted to share this:
Select Files by using check mark next to names.
Right click on Collapse All/ Expand All button with two arrows. (This button is on right side of Files to Commit box, and under Sync and Gear icons.) This is where Discard All Changes is >hidden<.
Sorry but too low level to add comment to #Leo wangs or #aspiringwebdev chain above. You gotta start somewhere...

Resources