open repo file instead of a tmp file to modify in git difftool
git difftool --tool=vimdiff --no-prompt HEAD~1 HEAD
git will open vim with two temporary files on the left and right side. Is there a way to force open the repo file on the right so that I can modify it directly?
git diff vimdiff
add a comment |
git difftool --tool=vimdiff --no-prompt HEAD~1 HEAD
git will open vim with two temporary files on the left and right side. Is there a way to force open the repo file on the right so that I can modify it directly?
git diff vimdiff
add a comment |
git difftool --tool=vimdiff --no-prompt HEAD~1 HEAD
git will open vim with two temporary files on the left and right side. Is there a way to force open the repo file on the right so that I can modify it directly?
git diff vimdiff
git difftool --tool=vimdiff --no-prompt HEAD~1 HEAD
git will open vim with two temporary files on the left and right side. Is there a way to force open the repo file on the right so that I can modify it directly?
git diff vimdiff
git diff vimdiff
asked Nov 15 '18 at 1:15
Justin LinJustin Lin
726
726
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
No: because you've selected two specific commits, there are no files to change.
That seems a little odd to say. It actually is a little odd, until you realize this thing about commits: while commits do contain files,1 the files they contain are frozen. None of them can ever be changed. They are committed, and the contents of any commit are as permanent as the commit itself,2 and totally read-only.
Of course, when you use Git, you have files that you can change. If you didn't, it would be hard to use Git. But those aren't the committed files: those are the work-tree copies. If you direct git difftool --tool=vimdiff to use those files as one side of the operation, it already does open those files directly. To do that:
git difftool --tool=vimdiff <options> <commit>
where <options> includes your --no-prompt and <commit> might be HEAD~1 again, for instance.
(As with git diff, git difftool can be told to compare two commits, or to compare one commit to the current work-tree. There is no option for comparing a commit to the current index contents. The rest of this answer does not mention the index, but the index holds a third copy of every file. Files inside commits are in a special, read-only, Git-only format. Files in your work-tree are in a useful format, so that you can read or edit them directly. Files in your index are in a halfway zone, between the HEAD commit where they're frozen and the work-tree where they're normal: the index copies are unfrozen, but still Git-only and compressed. Git makes new commits from the index copy, which is why you have to keep running git add all the time.)
1Technically, a commit doesn't so much contain the files as refer to the files. The files are stored using a series of indirections: commits point to tree objects, which give the name of the file, the mode, and a hash ID for the contents; and then the hash ID in the tree points to the Git blob object that saves the file's content. This allows two different trees (with maybe different modes or different sets of files) to re-use existing frozen file contents, and allows different commits (with maybe different authors or timestamps) to re-use existing frozen trees that re-use existing frozen commits. This is just one of several tricks that Git uses to save a lot of space, even though every commit stores a full and complete copy of every file: under the hood, there is a whole lot of re-use of old files.
2A commit normally lives forever, but if everyone who has some commit—as identified by some hash ID—agrees to stop using that commit forever and takes it out of the history-list, Git will eventually forget the commit for real. If anyone didn't agree, they can easily reintroduce the commit again, and in fact, that's the default. Commits are therefore hard to get rid of permanently once they've been spread to other Git repositories, because to get rid of them permanently, you have to ditch them from every Git repository that picked them up.
" This allows two different trees (with maybe different modes or different sets of files) to re-use existing frozen file contents"... and more recently, you have more trick to re-use existing content between forks! "Delta islands": stackoverflow.com/a/52458712/6309
– VonC
Nov 15 '18 at 5:43
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53311092%2fopen-repo-file-instead-of-a-tmp-file-to-modify-in-git-difftool%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
No: because you've selected two specific commits, there are no files to change.
That seems a little odd to say. It actually is a little odd, until you realize this thing about commits: while commits do contain files,1 the files they contain are frozen. None of them can ever be changed. They are committed, and the contents of any commit are as permanent as the commit itself,2 and totally read-only.
Of course, when you use Git, you have files that you can change. If you didn't, it would be hard to use Git. But those aren't the committed files: those are the work-tree copies. If you direct git difftool --tool=vimdiff to use those files as one side of the operation, it already does open those files directly. To do that:
git difftool --tool=vimdiff <options> <commit>
where <options> includes your --no-prompt and <commit> might be HEAD~1 again, for instance.
(As with git diff, git difftool can be told to compare two commits, or to compare one commit to the current work-tree. There is no option for comparing a commit to the current index contents. The rest of this answer does not mention the index, but the index holds a third copy of every file. Files inside commits are in a special, read-only, Git-only format. Files in your work-tree are in a useful format, so that you can read or edit them directly. Files in your index are in a halfway zone, between the HEAD commit where they're frozen and the work-tree where they're normal: the index copies are unfrozen, but still Git-only and compressed. Git makes new commits from the index copy, which is why you have to keep running git add all the time.)
1Technically, a commit doesn't so much contain the files as refer to the files. The files are stored using a series of indirections: commits point to tree objects, which give the name of the file, the mode, and a hash ID for the contents; and then the hash ID in the tree points to the Git blob object that saves the file's content. This allows two different trees (with maybe different modes or different sets of files) to re-use existing frozen file contents, and allows different commits (with maybe different authors or timestamps) to re-use existing frozen trees that re-use existing frozen commits. This is just one of several tricks that Git uses to save a lot of space, even though every commit stores a full and complete copy of every file: under the hood, there is a whole lot of re-use of old files.
2A commit normally lives forever, but if everyone who has some commit—as identified by some hash ID—agrees to stop using that commit forever and takes it out of the history-list, Git will eventually forget the commit for real. If anyone didn't agree, they can easily reintroduce the commit again, and in fact, that's the default. Commits are therefore hard to get rid of permanently once they've been spread to other Git repositories, because to get rid of them permanently, you have to ditch them from every Git repository that picked them up.
" This allows two different trees (with maybe different modes or different sets of files) to re-use existing frozen file contents"... and more recently, you have more trick to re-use existing content between forks! "Delta islands": stackoverflow.com/a/52458712/6309
– VonC
Nov 15 '18 at 5:43
add a comment |
No: because you've selected two specific commits, there are no files to change.
That seems a little odd to say. It actually is a little odd, until you realize this thing about commits: while commits do contain files,1 the files they contain are frozen. None of them can ever be changed. They are committed, and the contents of any commit are as permanent as the commit itself,2 and totally read-only.
Of course, when you use Git, you have files that you can change. If you didn't, it would be hard to use Git. But those aren't the committed files: those are the work-tree copies. If you direct git difftool --tool=vimdiff to use those files as one side of the operation, it already does open those files directly. To do that:
git difftool --tool=vimdiff <options> <commit>
where <options> includes your --no-prompt and <commit> might be HEAD~1 again, for instance.
(As with git diff, git difftool can be told to compare two commits, or to compare one commit to the current work-tree. There is no option for comparing a commit to the current index contents. The rest of this answer does not mention the index, but the index holds a third copy of every file. Files inside commits are in a special, read-only, Git-only format. Files in your work-tree are in a useful format, so that you can read or edit them directly. Files in your index are in a halfway zone, between the HEAD commit where they're frozen and the work-tree where they're normal: the index copies are unfrozen, but still Git-only and compressed. Git makes new commits from the index copy, which is why you have to keep running git add all the time.)
1Technically, a commit doesn't so much contain the files as refer to the files. The files are stored using a series of indirections: commits point to tree objects, which give the name of the file, the mode, and a hash ID for the contents; and then the hash ID in the tree points to the Git blob object that saves the file's content. This allows two different trees (with maybe different modes or different sets of files) to re-use existing frozen file contents, and allows different commits (with maybe different authors or timestamps) to re-use existing frozen trees that re-use existing frozen commits. This is just one of several tricks that Git uses to save a lot of space, even though every commit stores a full and complete copy of every file: under the hood, there is a whole lot of re-use of old files.
2A commit normally lives forever, but if everyone who has some commit—as identified by some hash ID—agrees to stop using that commit forever and takes it out of the history-list, Git will eventually forget the commit for real. If anyone didn't agree, they can easily reintroduce the commit again, and in fact, that's the default. Commits are therefore hard to get rid of permanently once they've been spread to other Git repositories, because to get rid of them permanently, you have to ditch them from every Git repository that picked them up.
" This allows two different trees (with maybe different modes or different sets of files) to re-use existing frozen file contents"... and more recently, you have more trick to re-use existing content between forks! "Delta islands": stackoverflow.com/a/52458712/6309
– VonC
Nov 15 '18 at 5:43
add a comment |
No: because you've selected two specific commits, there are no files to change.
That seems a little odd to say. It actually is a little odd, until you realize this thing about commits: while commits do contain files,1 the files they contain are frozen. None of them can ever be changed. They are committed, and the contents of any commit are as permanent as the commit itself,2 and totally read-only.
Of course, when you use Git, you have files that you can change. If you didn't, it would be hard to use Git. But those aren't the committed files: those are the work-tree copies. If you direct git difftool --tool=vimdiff to use those files as one side of the operation, it already does open those files directly. To do that:
git difftool --tool=vimdiff <options> <commit>
where <options> includes your --no-prompt and <commit> might be HEAD~1 again, for instance.
(As with git diff, git difftool can be told to compare two commits, or to compare one commit to the current work-tree. There is no option for comparing a commit to the current index contents. The rest of this answer does not mention the index, but the index holds a third copy of every file. Files inside commits are in a special, read-only, Git-only format. Files in your work-tree are in a useful format, so that you can read or edit them directly. Files in your index are in a halfway zone, between the HEAD commit where they're frozen and the work-tree where they're normal: the index copies are unfrozen, but still Git-only and compressed. Git makes new commits from the index copy, which is why you have to keep running git add all the time.)
1Technically, a commit doesn't so much contain the files as refer to the files. The files are stored using a series of indirections: commits point to tree objects, which give the name of the file, the mode, and a hash ID for the contents; and then the hash ID in the tree points to the Git blob object that saves the file's content. This allows two different trees (with maybe different modes or different sets of files) to re-use existing frozen file contents, and allows different commits (with maybe different authors or timestamps) to re-use existing frozen trees that re-use existing frozen commits. This is just one of several tricks that Git uses to save a lot of space, even though every commit stores a full and complete copy of every file: under the hood, there is a whole lot of re-use of old files.
2A commit normally lives forever, but if everyone who has some commit—as identified by some hash ID—agrees to stop using that commit forever and takes it out of the history-list, Git will eventually forget the commit for real. If anyone didn't agree, they can easily reintroduce the commit again, and in fact, that's the default. Commits are therefore hard to get rid of permanently once they've been spread to other Git repositories, because to get rid of them permanently, you have to ditch them from every Git repository that picked them up.
No: because you've selected two specific commits, there are no files to change.
That seems a little odd to say. It actually is a little odd, until you realize this thing about commits: while commits do contain files,1 the files they contain are frozen. None of them can ever be changed. They are committed, and the contents of any commit are as permanent as the commit itself,2 and totally read-only.
Of course, when you use Git, you have files that you can change. If you didn't, it would be hard to use Git. But those aren't the committed files: those are the work-tree copies. If you direct git difftool --tool=vimdiff to use those files as one side of the operation, it already does open those files directly. To do that:
git difftool --tool=vimdiff <options> <commit>
where <options> includes your --no-prompt and <commit> might be HEAD~1 again, for instance.
(As with git diff, git difftool can be told to compare two commits, or to compare one commit to the current work-tree. There is no option for comparing a commit to the current index contents. The rest of this answer does not mention the index, but the index holds a third copy of every file. Files inside commits are in a special, read-only, Git-only format. Files in your work-tree are in a useful format, so that you can read or edit them directly. Files in your index are in a halfway zone, between the HEAD commit where they're frozen and the work-tree where they're normal: the index copies are unfrozen, but still Git-only and compressed. Git makes new commits from the index copy, which is why you have to keep running git add all the time.)
1Technically, a commit doesn't so much contain the files as refer to the files. The files are stored using a series of indirections: commits point to tree objects, which give the name of the file, the mode, and a hash ID for the contents; and then the hash ID in the tree points to the Git blob object that saves the file's content. This allows two different trees (with maybe different modes or different sets of files) to re-use existing frozen file contents, and allows different commits (with maybe different authors or timestamps) to re-use existing frozen trees that re-use existing frozen commits. This is just one of several tricks that Git uses to save a lot of space, even though every commit stores a full and complete copy of every file: under the hood, there is a whole lot of re-use of old files.
2A commit normally lives forever, but if everyone who has some commit—as identified by some hash ID—agrees to stop using that commit forever and takes it out of the history-list, Git will eventually forget the commit for real. If anyone didn't agree, they can easily reintroduce the commit again, and in fact, that's the default. Commits are therefore hard to get rid of permanently once they've been spread to other Git repositories, because to get rid of them permanently, you have to ditch them from every Git repository that picked them up.
answered Nov 15 '18 at 2:02
torektorek
197k18246328
197k18246328
" This allows two different trees (with maybe different modes or different sets of files) to re-use existing frozen file contents"... and more recently, you have more trick to re-use existing content between forks! "Delta islands": stackoverflow.com/a/52458712/6309
– VonC
Nov 15 '18 at 5:43
add a comment |
" This allows two different trees (with maybe different modes or different sets of files) to re-use existing frozen file contents"... and more recently, you have more trick to re-use existing content between forks! "Delta islands": stackoverflow.com/a/52458712/6309
– VonC
Nov 15 '18 at 5:43
" This allows two different trees (with maybe different modes or different sets of files) to re-use existing frozen file contents"... and more recently, you have more trick to re-use existing content between forks! "Delta islands": stackoverflow.com/a/52458712/6309
– VonC
Nov 15 '18 at 5:43
" This allows two different trees (with maybe different modes or different sets of files) to re-use existing frozen file contents"... and more recently, you have more trick to re-use existing content between forks! "Delta islands": stackoverflow.com/a/52458712/6309
– VonC
Nov 15 '18 at 5:43
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53311092%2fopen-repo-file-instead-of-a-tmp-file-to-modify-in-git-difftool%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown