How to compare two files in two revisions with TortoiseGit? - tortoisegit

I've moved a function from one file to another, and I'd like to compare the moved version to the original, so I'd like a diff with the source file on the left and the destination file on the right. Using TortoiseGit I can figure out how to diff two files in the working tree, or diff one file across multiple commits, but not both at once. Is it possible without checking out the two files?

There is a way to do this (but not an obvious direct one):
Open the log dialog and navigate to the commit/file you want to diff. Drop it into Explorer or select "Save revision to..." and then select the two files you want to compare and select TortoiseGit -> Diff.
If the file is modified or was already committed in the meantime then you can also open the log dialog (make sure so that both files are in the history, e.g., by opening the log on a common directory). Select the commit of the first file and click on "Mark for comparison" in the context menu of the file, then navigate to the commit of the second file and select "Diff with ...".
UPDATE:
Starting with TortoiseGit 2.10.1.0 (preview release) you can select a file in Explorer and mark it using TortoiseGit -> "Diff later" and compare a file to this file from Log Dialog or Repository Browser using "Diff with ..." as described above.

Related

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.

Is there a way to have a global diff before doing a checkin in TFS

With Visual Studio and TFS, is there a way to have a diff showing in a single page changes for each file before doing a checkin ? Instead of having to do diff of each file one after the other.
Similar to the UI of GitHub for Windows when doing a commit:
file1
diff
file2
diff
...
Thanks,
Edit: as mentioned by Jehan33 the view I'm looking for looks like this (it's available on the web portal AFTER a commit):
This view is available after the check-in for the change sets where it will display all the file differences for a changeset in single page in web portal. Its not possible to do the same before the check-in.
Assuming your are using Team Foundation Version Control. If you right click on the folder where you have pending changes and click Compare. Select the options
"Show Items that exists only in source path", "Show Items that exists only in target path" and "Show items that are different", you will get the desired view.
The closest thing I've found was Diff All Files.
You can choose to combine all changed files into one and compare. Sadly there is no 'lines of context', however the code is open source and you can choose an external diff tool which may achieve this.

Add command in TortoiseGit

I'm just beginning to use TortoiseGit for Windows (I'm new to git) and I don't see the Add command in the context menu when I right-click on a directory or file. As I understand it, I should run this addcommand each time I want an update to a local file to be "staged". Here I don't see such a thing, the only "similar" thing I can do is run a commit instead, which is obviously not the right thing to do.
Besides, when I create a new file I also want to add it, but the context menu only proposes to "Add to ignore list".
Am I missing something here?
You can add a file or folder to a git repository by right-clicking on it, then in "TortoiseGit"-submenu select "Add.." (should be the first menuitem, right above the "Add to ignore list"-submenu).
Anyway... another way of staging files or folders via TortoiseGit is to right-click the repository > TortoiseGit > Check for modifications > select the filed/folders you wish to stage from the list of not versioned files > right-click > add.

How to create a patch in TortoiseSVN while no file is checked out?

I know if some files are checked out (modified) then I could right click on containing folder, then select "create patch". After then I will see list of all checked out files. So I could include them in the patch.
But when no file is checked out, aka everything is committed, create patch window is empty. So the question is how can I create patch from checked-in files? I want to send this patch to colleagues so they can apply them on company svn server.
thanks,
A unified diff is a patch file.
Using TortoiseSVN, right-click on your working folder and select “Show Log”
Select the two revisions (Ctrl-Click)
Right-click on either of the highlighted revisions and select “Show differences as unified diff”
To save the changed files with the folder structure.
Using TortoiseSVN, right-click on your working folder and select “Show Log”
Select the two revisions (Ctrl-Click)
Select "Compare revisions." This would list the modified files between the revisions in a dialog box
Select all the files in the dialog that comes up. Right-click on the selected files and select "Export selection to…"
This should export the modified files with the folder structure.
What you're describing is a diff between two subversion revisions. Check out the SVN Book's section on svn diff to see how to do it.
If you just want colleagues to get the most up-to-date files, they should get it from the svn server using svn-checkout. If for some reason they can't access your svn server, you can also right-click and choose svn-export; this gives you a set of all the files in the containing folder without any of the hidden .svn directories.

Git (TortoiseGit) - How to revert a single file to a previous revision and then undo the revert?

When using Git with TortoiseGit: Does somebody know how to revert a single file(or a complete repository) to a previous revision?
For example I have a repository containing multiple files. One file exists in three revisions (1 ; 2 ; 3). Now I want to change from revision 3 back to 2.
TortoiseGit offers a "Revert" function in the "Show log" dialog which allows to jump back to a specific revision, but this will revert your whole repository instead of a single file.
Also once I have reverted something, I don't have a clue how to undo the revert and jump back to the newest revision.
From the command line: git checkout is probably what you want.
The documentation shows an example of:
$ git checkout master~2 Makefile
to revert Makefile to two revisions back in the master branch
From within TortoiseGit (via Windows Explorer) it looks like you can do this with the following steps:
Navigate in Explorer to the folder where the file is.
Right-click on the file you want to revert, choose Show log from the TortoiseGit context menu
In the top section ("graph") select the revision that has the version of the file you want to revert to
In the third section (file list) right-click the file and choose Revert to this revision
You should get a message like 1 files revert to e19a77
It is also possible to get a specific file:
Right-click on the file
Choose the menu item: Git Show Log
TortoiseGit show a dialog with a list of all revisions
Click on the prior revision (2)
In a list in the bottom of the dialog it shows all the files associated with the commit
Find the file you are looking to view
Right-click on that file and Save Revision To
This will save that previous revision of the file with the commit number concatenated on the file
For example:
- original file is file.txt
- revision 2 will save as file-67b51a8.txt
I'm using TortoiseGit v2.2.0.0
In TortoiseGit the answer is to right-click the project folder and click Show Log, then right-click the change you want to roll back to and click Switch/Checkout to this... . It will let you then proceed from that weird place in the commit stack, or branch in case you plan to commit and want things to stay sane.
Updated my answer, based on these comments:
by Alexander.
by mlibby
by Chris Moschini
Suppose the working tree is clean and you want:
Checkout some file(s) of its previous revision
Testing
Revert to current revision
Checkout some file(s) of its previous revision
(a) Right click the file you want to revert and Show Log for that file
(b) Right click the file in file list and perform Revert to parent revision
(c) repeat (a), (b) until you get all files you want.
Testing
Revert to current revision
(a) perform Revert... in context menu of explorer
This way, you can choose the file(s) you want to revert.
(b) or this quick way: perform Reset Hard in Log dialog
This way, all changed files revert. (=> Lost all working dir changes)
(Tested on TortoiseGit 1.8.16.1, GfW 2.6.4.windows.1, Win 10 64bit)
For Tortoise Version 2.3.0:
You can do it in several ways, but fastest i think is that:
Right click on the file
Click the menu option "Diff with previous version"
Right click on the left (previous) version of file
Click the menu option "Use this whole file"
Save the changes (ctrl+s)

Resources