Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I edit the current revision of a file from diff view between current and a revision older than the latest one?

In Visual Studio (if you're using a git repository) you can right-click a modified file and select "Compare with unmodified". There you can see a diff in which you can edit the current version of the file. To clarify: You can edit your current uncommitted changes in source files, in a diff view compared to the latest commit. To contrast that, comparing 2 commits in diff view only shows you read-only copies of these files in temp folder which you cannot edit.

But when you're looking at a diff between the current revision and some older revision (by selecting the top commit and one of the older ones with Ctrl-click and in the right-click menu selecting "Compare commits...") you cannot edit the files from the current revision.

Is there a way to enable editing the current revision files in diff view in Visual Studio when comparing any older revision (not just the previous one) with the current revision?


Side note: One weird trick which developers hate is resetting to the desired older revision with "keep changes" and making a commit, thus making it possible to "compare with unmodified" as if it was a previous commit. But this is hacky and undesirable.

like image 843
user1306322 Avatar asked Apr 09 '18 12:04

user1306322


People also ask

How can I see diff between previous commit?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch.

Which command will show the differences between the staged and committed versions of the file?

The git diff command shows the differences between the files in two commits or between your current repository and a previous commit.

Which command shows the changes between commits?

"git diff" always show the difference between two commits (or commit and working directory, etc.).

What is the use of git diff command?

Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.


1 Answers

This is unfortunately not currently supported when diffing two versions from the VS 2017 Git History tool window, even if one of the versions is the current workdir version. We also don't currently have the ability to choose a specific version with which to do the diff from the Changes page. I will add this to our backlog for consideration for a future Visual Studio release.

As you noticed, the diff is sometimes editable from the Git Changes page in Team Explorer. Here's a summary of how we determine if the diff window will be editable.

  • Workdir changes only:
    • Diff workdir with HEAD, workdir content editable in diff.
  • Staged changes only:
    • Diff workdir with HEAD (since workdir content matches index), workdir content editable, changes to workdir are not automatically staged.
  • Staged and workdir changes:
    • Diff staged with HEAD, staged content is read-only.
    • Diff workdir with index (staged), workdir content is editable.

Hope this helps, and thanks for raising this question.

like image 167
Chad B Avatar answered Sep 20 '22 16:09

Chad B