How to access the text in the diff view of sourcetree?
Asked by bendwarn:

Sometimes I want to patch the staged file with deleted texts. It would be convenient if I can select and copy them.


Answers:
author: QwazyWabbit
body: If I understand your question correctly, you want to copy-paste text from a staged file using the diff view of SourceTree into another file or from a file into the staged file.

To copy from the diff view, simply select the text in the view and do a ctrl-C / ?-C and ctrl-V / ?-V it anywhere.

The copy command is also available from a right-click context menu once you have selected the text in the diff view.

As for modifying the staged file, you should probably be editing it in your primary editor. It will be updated and re-staged after you've saved the file in that editor and SourceTree senses the change.

comments: author: bendwarn
body: Thanks. The shortcuts works, though it only copies one entire line.

Because selecting in diff view is lame, it cannot choose just words or multiple lines.

Also, right-click context menu cannot appear in diff view.

Where can I issue a ticket for those function?


author: Seth
body: On Windows, you can select multiple lines, but selecting words or using right-click are not possible.


author: bendwarn
body: Thanks, It's not dragging to select, but with shift. Now I see.

But it is kind of buggy. If you select a line and click the lines under it with shift, that works fine, But clicking upward is weird, which will unselect your previous selection and select next line.


author: Seth
body: Yep. That's all you've got to work with in the built-in diff.


author: QwazyWabbit
body: I agree, it feels buggy and incomplete. It's not consistent between Windows and Mac platforms either, except for shortcut keys. FWIW, I typically use FileMerge on Mac and WinMerge on Windows for external diff tools. If I need a selective merge those are my tools of choice.

Right-click in diff view works on Mac but not on Windows. Clearly, a difference in behaviors between the platforms.

To report these issues, use Help \| Report bug... in Windows; Help \| Open a ticket on JIRA in Mac version. They're using their own tools to manage their bug list.

In my experience Eric, i've yet to use the diff view in the manner you propose, I've always selected whole lines or blocks at a time for copy-paste and never tried spanning them or ctrl-select them. I'm either pulling whole commits or finding a change block to do a quick copy-paste from one project into another and never needed much else. It's not what the tool is about, IMHO. I'd still support your reporting it as a bug, especially the lack of context menu on Windows version.


author: bendwarn
body: There is the issue.

<https://jira.atlassian.com/browse/SRCTREEWIN-3638>


author: thinsoldier
body: What program do you have configured as your external diff tool?

I can select a file and press cmd+D to have the selected and previous versions open in my text editor side by side in diff mode.

For older versions I can right click the file and "open selected version" to open the file at the state it was in for that commit.


author: Seth
body: You can use the git command line, or lunch the external diff tool from Sourcetree.