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

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.

Related

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

How to exclude changes when commiting in VSTS / Azure devops?

When using TFS, it is simple to exclude changes in Visual studio just by right clicking.
How can I do the same in VSTS which is now Azure devops? I have a repository with multiple solutions and i only want selected changes in a particular solution to be committed and pushed to the server. But how to perform this operation?
When using Git, you can stage changes you want to commit. If you have staged changes, all other unstaged changes will not be part of the commit. Staging a file is simply preparing it to be committed.
When you do not stage changes in Visual Studio, by default all changes are committed. See the left side of the image below: the button says 'Commit all'. The changes are all grouped together. If you commit like this, all changes would be committed.
In the right part of the image, you can see there are Changes, and Staged Changes. The commit button's text has changed to 'Commit Staged'. If you commit like this, the Notifications.cs file would be part of the commit, the News.cs would not be part of the commit.
You can (un)stage changes in Visual Studio by right clicking them and selecting (un)stage. You can also selecting the files to (un)stage and using the plus sign at the top right of the Changes to stage, and the minus sign at the top og the Staged Changes to unstage.
In short: by staging changes, you can determine which changes are included in the commit you're about to create. Here's some more information on Git Basics, the below information about staging can be found at the bottom of that article.
The staging area is a file, generally contained in your Git directory, that stores information about what will go into your next commit. Its technical name in Git parlance is the “index”, but the phrase “staging area” works just as well.
The basic Git workflow goes something like this:
You modify files in your working tree.
You selectively stage just those changes you want to be part of your next commit, which adds only those changes to the staging area.
You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.

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.

Can you do partial commit in TortoiseGit?

Native git allows partial commits: You can commit only some of the lines of your file and leave the rest for a later commit.
Is this possible in TortoiseGit?
Yes, there are official instructions in the docs.
In practice, I find this workflow useful:
Right click a file you want to partially commit
Click Restore after commit - This immediately creates an internal copy of the file.
Double click the file to edit in TortoiseGitMerge
Right click -> Mark this block for each change you want to commit now
Right click -> Leave only marked blocks to revert the other changes.
As an alternative to these two steps, you can edit the file the way you want.
Save and Close TortoiseGitMerge
Commit - this restores the internal copy of the file afterwards.
The changes you just reverted in TortoiseGitMerge are now restored in your working tree.
Update:
Starting with TortoiseGit 2.13 TortoiseGit comes with a partial staging feature in the commit dialog.
You need to enable the partial staging feature on the commit dialog, then the can open the patch view on the right side and select lines/hunks to stage/unstage.
The answer https://stackoverflow.com/a/32527098/3906760 is basically correct, however there are fewer steps required.
Choose Restore after commit in the context menu of the file you want to partially commit - This immediately creates an internal copy of the current state of the file.
Now adjust the file to only contain the changes you want to commit
This can be done using any editor you want to use, but also using TortoiseGitMerge:
Double click the file to edit in TortoiseGitMerge (or your configured diff tool)
Adjust the file to only contain the changes you want to commit.
Save and Close
Commit - this commits the selected files and restores the internal copy of the file - the original state of the file is now in your working tree again.
These steps are required as TortoiseGit does not yet support the full staging process and hunk/block selection, cf. https://tortoisegit.org/issue/2299.

How do I revert back to earlier commit using source tree

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.

Resources