obsidian-git icon indicating copy to clipboard operation
obsidian-git copied to clipboard

[Feature]: Force pull / reset --hard HEAD

Open mubanga90 opened this issue 1 year ago • 10 comments

Would be super helpful to have the options to do a git pull --force that way when my phone and PC get out of sync I could easily fix things on my PC and get my phone back in sync without me having to remove the whole vault from my phone and cloning it again.

Seems like some others are also looking for this feature:

https://github.com/denolehov/obsidian-git/discussions/616

Update: as @Vinzent03 mentioned it should not be git pull --force instead it should probably do:

git fetch
git reset --hard HEAD

mubanga90 avatar Mar 01 '24 18:03 mubanga90

I don't think git pull --force is what you all are really searching for. As described in this article, I think you want a command which resets the working directly and then pulls.

Vinzent03 avatar Mar 04 '24 20:03 Vinzent03

same problem here..

slnw avatar Mar 07 '24 09:03 slnw

I actually see now that the command "CAUTION: Discard all changes" already exists. After calling that command, the pull command should work.

Vinzent03 avatar Mar 12 '24 12:03 Vinzent03

@Vinzent03 I don't think ignoring the changes would help if the conflicting changes are already committed.

Having a hard reset option would be a great feature.

KhudaDad414 avatar Apr 29 '24 13:04 KhudaDad414

What exactly do you mean with the conflicting changes are already committed. Doesn't this mean the merge commit is already done and the pull therefore ended successfully. I don't see the difference between "hard reset" and the provided command.

Vinzent03 avatar May 09 '24 21:05 Vinzent03

@Vinzent03 thanks for responding. Here is what happens:

  1. Device 1 makes some changes and commits.
  2. Device 1 pushes the changes to remote.
  3. Device 2 makes some changes and commits.
  4. Device 2 tries to pull the changes before being able to push it's commit.
  5. Device 2 Fails to pull since it already has conflicting changes in the commit.
  6. Since there is no option to resolve the conflicts, the user is forced to delete the entire Vault in Device 2 and download the Vault from remote again.

How does a hard reset help? by doing a "hard reset" Device 2 will ignore it's committed changes and overrides everything with the remote's changes.

Hope it's clear.

KhudaDad414 avatar May 15 '24 10:05 KhudaDad414

This is extremely annoying. It would be great if you could add the hard reset/

@mubanga90 how do you fix this currently. Recreating the repo also deletes my settings.

mgrottenthaler avatar May 30 '24 12:05 mgrottenthaler

@mgrottenthaler I've gotten a lot better at always syncing and closing obsidian when switching. When I do forget CAUTION: Discard all changes as @Vinzent03 pointed out works most of the time.

When it doesn't I don't recreate the repo:

  • I delete vault (you will loose all changes on that device)
  • Recreate the vault
  • Add Obsidian Git
  • Fill in my credentials
  • Clone the Repo
  • All other plugins and settings should then be back

But like I said I only had to that once or twice in the past months

After reading this, I suspect that it would also prevent to get into this situation if there was a good working way to merge changes from both sides. I made a custom 'sync' command with the extension 'better command palette' which aims at that to some extent (doing pull, commit, push), but of course I am also running into conflicts frequently on mobile. Maybe using merge via #572 would solve a lot of that?

mmoole avatar Jun 01 '24 14:06 mmoole

One workaround: https://github.com/Vinzent03/obsidian-git/issues/340#issuecomment-1435836523

wangyandongnx avatar Oct 13 '24 15:10 wangyandongnx