kometenstaub / obsidian-version-history-diff

Get a diff view of your Obsidian Sync, File Recovery and Git version history
MIT License
115 stars 5 forks source link

`git obsidian error: fatal: path 'my-file-path' exists on disk, but not in '9b812828....'` #7

Closed kometenstaub closed 1 year ago

kometenstaub commented 2 years ago

After renaming a file with git mv, clicking on an old version for getting the file content of that version yields this error.

I would need a way to determine what the file name was before the renaming. The git log API does not provide any info concerning this.

Fixing this should work by refactoring the git view to not work on file contents, and instead use the hashes to get the diffs.

cc @Vinzent03 - What is your take on that?

kometenstaub commented 2 years ago

The other thing that would need to be addressed is how to get the file content of a file that has been renamed. I have only been successful with git show when I used the old file name for a commit before the rename happened. I've only tried it on the command line so far and didn't look into whether simple-git can deal with it.

tim-hilde commented 2 years ago

Any news on this?

kometenstaub commented 2 years ago
git log --follow <path-to-file>

That also shows all the commits before the file was renamed, but it doesn't tell me the name of the file in these former commits, meaning I cannot do

git show <SHA> -- <path-to-file>

I'd need to find the commit (so git log <path-to-file>, then the last commit) where the file was renamed, then query for rename from <old-path> (but that probably depends on the OS language as well :slightly_smiling_face:) and get the new file name in the line below it. Then

git log <old-file-path>

would get the other SHAs.

While all of that is possible, I'm not going to implement that for the time being, but a PR could be an option.

joellti commented 1 year ago

Just wanted to voice my need of this being addressed since i refactor my notes quite often by moving them around and without this being addressed all the changes made to the notes before their last moves won't be displayed properly.

Vinzent03 commented 1 year ago

@kometenstaub Hey I think I found a way to ship the old file name of a file with the result of the log method. This should help you right?

kometenstaub commented 1 year ago

@Vinzent03 If that means that I can call the API with the current file name and get contents from before the rename as well, yes.

Vinzent03 commented 1 year ago

@kometenstaub 2.17.0 should now include the fileName parameter for each array element of the log result. You should be able to use that name with git show then.

kometenstaub commented 1 year ago

@Vinzent03 Thank you, I’ll look into it.