obsidian-git
obsidian-git copied to clipboard
Idea: Show git blame next to each text line
Hi, I don't know if this idea falls into the topic of this module at all, but as I did not find any other git modules for Obsidian, I'll post this here.
I store my Obsidian vaults in git repositories, and I would like to see when did I last modify each text line. I do programming too, and in various JetBrain's programming editors (e.g. PhpStorm, PyCharm, which are based on Intellij IDEA) there is a possibility to open a wider line number panel which contains git blame information: name of the last committeer and date and time. Here is a video that demonstrates this feature:
https://youtu.be/R8QW8s4Ibio?t=38
You don't need to watch the whole video. I made the link so that it starts from the part where the git blame information is visible. You'll get the idea from just one glance.
Even though writing Markdown files with Obsidian is not programming, and text lines in Obsidian are not code lines, the git blame information is still applicable to the text content of Obsidian too.
I have actually written a message about this idea in Obsidian's forum too on December 2020 but I guess this kind of idea can have a better chance of being implemented, if it's suggested for a module rather than the main product.
If this idea does not suit for this module, feel free to decline. :)
I see your point, but there are some problems though.
- The git library doesn't expose that information
- adding a scroll sync side pane is hard and adding it inline like in vscode would need some more html/css skills
Will close it for now, because I see no way to implement this.
I know this is a wontfix for now, I was going to create another feature request but found this issue.
Whenever the git lib enables and @Vinzent03 decides to implement it, I believe that the gitlens implementation is more elegant and less hardcore than a full out IDE as shown in the video. It shows as unselectable faint text on the focused line and at start of classes (headers in obsidian):
On hover and click it shows/goes to the commit info
I agree with you and I think I even saw something similar on the obsidian discord with the new editor, but the data source is still missing. I may be able to convert the output myself though, but I'm unsure. EDIT: Just to make it clear. I'm not working on this currently, but when I get the time, I will investigate.
@Vinzent03 I could offer help in implementing this - or even take over the full feature. I would also like to have this feature for the same reasons as the issue creator said.
I have however not looked into the plugin at all - and I don't know, how it would need to be implemented. Are there any "important thoughts" regarding the implementation approach from your side?
Other than that, it needs to be further discussed how exactly the feature should look like and what it should contain.
While the line implementation shown by @rzfzr is easiet to implement, I feel like it would be not quite what I was looking for myself. Concretely, I can imagine getting distracted quite easily when this thing is there everywhere when I click on a line. (Though one could imagine a quick hotkey to toggle this display.)
I am personally rather on the side of having a minimal colorbar on the left side near the line numbers. The colorbar would corresponding to the age of the last change of the line. Clicking on the colorbar / line-numbers would then show more information.
What do you all think about the suggestions?
@GollyTicker I appreciate your will to help. To be honest, I really like the way VS Code integrates Git in the file view. They have colors on the lift indicating whether a line has changed, new, or is deleted. So I would prefer rzfzr's way by showing it in each line. Although I somewhat like your way as well. I will do some research in the Discord checking the possibility of the different approches.
Regarding implementation, the repo contains now two git implementations. One for system installed git and one for mobile, where Git is reimplemented in JS. I would start and focus on the simpleGit.ts
file, which uses the system Git.
Other than that, it needs to be further discussed how exactly the feature should look like and what it should contain.
Personally, I have two bare minimun properties that I think it should contain for my use case:
- Commit date with customisable format.
- A way to get the commit hash. I'd prefer to be able to copy it to the clipboard. E.g. a small icon button that you click to copy to clipboard. Hover over the icon to see the commit hash as a tooltip text - this way the hash can be read, but it won't consume any space on the UI. Perhaps add commit message to the tooltip?
Others may probably need the author name, too, but if that's added, there's a number of options on how it can be displayed:
- First name + last name: John Smith
- First name or last name only: John or Smith
- Initials: JS
- Email: [email protected]
Maybe I'd start with just having the possibility to display the email? Add others later, if needed.
While the line implementation shown by @rzfzr is easiet to implement, I feel like it would be not quite what I was looking for myself. Concretely, I can imagine getting distracted quite easily when this thing is there everywhere when I click on a line. (Though one could imagine a quick hotkey to toggle this display.)
I agree.
Maybe @rzfzr's idea could be an aternative. Develop one of the ideas first, and the other sometime later. I like the fact that the @rzfzr's method does not require any kind of extra clicking to get the commit info visible (as opposed to the line number pane thing, which would require a click to expand the pane). But it only shows the info for one line at a time. Sometimes I'd like to see the info for all lines at one glance.
I guess @rzfzr's method does not support adding a clickable icon for copying the commit hash? Or does it? But another solution could be to create an Obsidian command that copies the commit hash of the current line to the clipboard.
I am personally rather on the side of having a minimal colorbar on the left side near the line numbers. The colorbar would corresponding to the age of the last change of the line. Clicking on the colorbar / line-numbers would then show more information.
I agree, the colorbar is important. It makes it easy to differentiate different commits easily when the color is different - really handy if there are multiple commits made during the same day. I also agree on clicking the colorbar / line numbers to toggle the commit information on or off.
I really like the way VS Code integrates Git in the file view. They have colors on the lift indicating whether a line has changed, new, or is deleted. So I would prefer rzfzr's way by showing it in each line.
JetBrains has this too: it can be combined to the idea of the video in my first post. If a line has been modified (but not committed), JetBrains does not show the latest commit info of that particular line, but instead just colors: green if the line is new, blue if it's modified or a small triangle if a line is deleted between two lines. I like this, but I would implement it in a way that would not block seeing the information about the last commit to the line, too.
Here's a screenshot from JetBrains' WebStorm:
I guess @rzfzr's method does not support adding a clickable icon for copying the commit hash? Or does it? But another solution could be to create an Obsidian command that copies the commit hash of the current line to the clipboard.
vscode does, if you hover the commit message you get a popup with different options, I also get the same view you showed from jetbrains:
vscode is also an electron app, maybe some stuff can be highly inspired... 👀
Ideally this discussion won't matter a whole lot, the backend being the same and the visualization methods being togglable in the settings, I bet someone will want this info right in the file explorer, either by date or color-coded.
Regarding implementation, the repo contains now two git implementations. One for system installed git and one for mobile, where Git is reimplemented in JS. I would start and focus on the simpleGit.ts file, which uses the system Git.
@Vinzent03 Yup. I'm looking into it and working on it. Thx for the info.
Looking at the various responses yet, I'll be looking for the following proposals and try oout a few of them to see what works well for the beginning:
- must: coloring of a bar side to line numbers indicating age of last change. toggleable.
- optional: this also includes Jetbrains style new lines and "deleted lines"
- must: configureable info displayed left to the line-numbers. toggleable.
- optional: formatable date, configurable name author/email display etc.
- must: copy last change commit hash for a certain line to clipboard
- optional: commit information on the same line. transparency to ensure it does not distract. toggleable
- optional: widget showing extra information on the commit (ie. vscode screenshot from @rzfzr)
I'll see what I can make in the next days or so. Will update screenshots and relevant developments.
Development branch: https://github.com/GollyTicker/obsidian-git/tree/line-author-info
Thank you @GollyTicker ! ❤️
#288 @Vinzent03 Can you give me some early feedback regarding the dev tooling? As PR for details.
:information_source: Early progress status with a first GIF: https://github.com/denolehov/obsidian-git/pull/288#issuecomment-1229502314
:information_source: Most "must" features are implemented now: https://github.com/denolehov/obsidian-git/pull/288
Next steps:
- make commit hash copyable
- finalise visuals (e.g. adaptive to light/dark mode, fix certain spacing issues)
- handle edge cases (e.g. new and untracked file)
- improving code quality
- testing complex logic
- code review and merge
:information_source: The feature is as good as finished and ready for beta-testing! :information_source:
I'd be very happy, if some of you would like to try out and beta-test this feature. Look into the pull request for how to do that.
Thank you! I will do beta testing at some point, but I don't know yet when I'll have time for it. At least this week is very busy for me. I'll come back to you! 😎👍
I had to resolve quite a few things, but now it works. This line author info now also works for the new Obsidian v1.0 release!
Feature was implemented and will be released in a new version soon! 🥳
Released in 2.20.0 🥳🥳✨✨
Update your local Obsidian-Git plugin 👉 https://github.com/denolehov/obsidian-git/releases/tag/2.20.0