denolehov / obsidian-git

Backup your Obsidian.md vault with git
MIT License
6.12k stars 251 forks source link

[Bug]: files in gitignore not being ignored #688

Closed back-lacking closed 4 months ago

back-lacking commented 5 months ago

Describe the bug

The error is exactly what it says on the title. I listed one file in my gitignore (.obsidian/workspace.json) however that one particular file wont be ignored. that would cause pulls and pushes to fail due to that one file not being ignored and file conflicts. (this issue is also present on windows, same behavior)

Relevant errors (if available) from notifications or console (CTRL+SHIFT+I)

git obsidian error: Pull failed (merge): error: Merging is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.

plugin:obsidian-git:44193 git obsidian message: Everything is up-to-date
plugin:obsidian-git:44203 git obsidian error: You have conflicts in 1 file
plugin:obsidian-git:44203 git obsidian error: Pull failed (merge): fatal: You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you merge.

plugin:obsidian-git:44193 git obsidian message: Everything is up-to-date
plugin:obsidian-git:43742 Pushing....
plugin:obsidian-git:44203 git obsidian error: To https://gitlab.com/back-lacking1/obsidian-notes.git
!   refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
Done
Pushing to https://gitlab.com/back-lacking1/obsidian-notes.git
error: failed to push some refs to 'https://gitlab.com/back-lacking1/obsidian-notes.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details

Steps to reproduce

setup remote git repo add .obsidian/workspace.json to git ignore make whatever notes you need/want press the "backup" button see git error due to file conflicts (windows sees the same process)

Expected Behavior

workspace.json gets ignored when pushing changes and pulling changes.

Addition context

No response

Operating system

Linux

Installation Method

Flatpak

Plugin version

2.22.0

Vinzent03 commented 5 months ago

I assume you already committed the file before adding it to .gitignore. You need to run git rm --cached <file> to remove it from the repo.

back-lacking commented 4 months ago

I assume you already committed the file before adding it to .gitignore. You need to run git rm --cached <file> to remove it from the repo.

so ive done that, tried it for a few days, made a few changes, and i still see the file being modified. im looking at the commits on gitlab (obsidian notes stored on there), i would see the workspace.json file as a file that is modified. ive tried to remove workspace.json from the gitlab repo, but that didnt succeed.

Vinzent03 commented 4 months ago

I can assure you that if you properly write your .gitignore file and to the rest correct, it will work. Did you commit after running git rm --cached .obsidian/workspace.json? What do you mean with deleting the file from gitlab didn't work? If you run the rm command locally, commit and push, the file should be removed on gitlab as well. If you now do some changes in obsidian, the workspace.json file should be ignored.

back-lacking commented 4 months ago

Im not sure if i pushed the change. I will look at the commit log on gitlab. I will do it again in a couple minutes in order to confirm. I commited and pushed the gitignore seperately. Ran the git rm command, not sure if i pushed the change. The git ignore is just one line, .obsidian/workspace.json

back-lacking commented 4 months ago

image here is the commits related to changing the gitignore and removing workspace.json. image here is the commit related to the gitignore.

Vinzent03 commented 4 months ago

But is the file now deleted in the repo on gitlab? You deleted the workspace file before fixing your .gitignore. If not try again to delete the workspace file via my provided rm --cached command.

back-lacking commented 4 months ago

i may be very dumb just checked the gitlab repo, and workspace.json isnt there

back-lacking commented 4 months ago

as for how i deleted the workspace.json file, i deleted it from the gitlab repo using gitlabs "delete file" option

back-lacking commented 4 months ago

image basically, went to the file, and pressed delete. which automatically made a commit for deleting the file also, im checking the other commits i made that day, seems like the workspace.json wasnt included in the commits. there are a few commits that did include changes to workspace.json. (made after the commits for deleting the json and changing git ignore). i also use this on windows so ill see if the same issue is replicated on windows.

Vinzent03 commented 4 months ago

I'm really confused by your new edits. I see you are not familiar with git and this is not a support forum for git. So I will try it last time. Go into terminal and delete the workspace.json file like I told you. The file should be marked as deleted now in git status. Now commit and push the changes. The file should now also be gone from the gitlab repo.

back-lacking commented 4 months ago

image shit (same thing on windows)

Vinzent03 commented 4 months ago

As this is not an issue with the plugin, please try to find other sources on the internet to fix your issue. Like this one: https://www.atlassian.com/git/tutorials/saving-changes/gitignore I can't explain you every step on how to use git, now that you are even talking about multiple machines.

back-lacking commented 4 months ago

fair enough, i will take a look at that article when i can.