twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
13.36k stars 493 forks source link

How does merging work? #3092

Closed vdawg-git closed 1 year ago

vdawg-git commented 1 year ago

What exactly are you trying to do?

I have some configs which get partly edited by other apps. Now I want to merge all changes of all the files.

What have you tried so far?

I setup my configuration as specified in the docs:

merge:
  command: "nvim"
  args: ["-d", "{{ .Destination }}", "{{ .Source }}", "{{ .Target }}"]

but do not quite understand the process and vimdiff. Which file should be saved to update my tracked config?

What is the difference between destination and target?

How can I save and go to the next merge? (:w and :qa does close Neovim and wont lead me to the next merge ) I know this is not directly related to chezmoi, but finding good resources about that turned out harder than expected (I mostly found things about neovim git plugins )

And thank you for creating this awesome tool!

Where else have you checked for solutions?

twpayne commented 1 year ago

So, firstly, if everything is going well then you should never have to use chezmoi merge. Merging is for when the dotfiles in your home directory have drifted significantly out-of-sync with your dotfiles in your repo.

I setup my configuration as specified in the docs:

merge:
  command: "nvim"
  args: ["-d", "{{ .Destination }}", "{{ .Source }}", "{{ .Target }}"]

but do not quite understand the process and vimdiff. Which file should be saved to update my tracked config?

You need to save {{ .Source }}. An explanation:

{{ .Destination }} is the file in your home directory (the destination). {{ .Target }} is what chezmoi thinks the file in your home directory should contain. {{ .Source }} is the file in your source directory.

If you're not using templates then {{ .Target }} and {{ .Source }} will be the same. If {{ .Source }} is a template then {{ .Target }} will be the result of executing that template.

Generally, when you're using chezmoi merge, you'll be copying lines from {{ .Destination }} to {{ .Source }}, i.e. copying changes from your home directory back into chezmoi's source state.

How can I save and go to the next merge? (:w and :qa does close Neovim and wont lead me to the next merge )

This depends on your merge tool. :wqa should work, as chezmoi merge invokes your diff tool once per file that needs merging.

I have some configs which get partly edited by other apps.

In this case, you should read about how to manage part, but not all, of a file.

And thank you for creating this awesome tool!

Thank you!

vdawg-git commented 1 year ago

Thank you so much! Thats perfect