When editing source code using gvim (v.7.4.488), I want to commit some changes the vcs (I'm using git 2.1.4 from the command line in Ubuntu linux).
git --status
shows which files I changed. However, it also shows the vim .*.swp
of the currently visible buffer(s) (both if the file contain unsaved changes and when the edited file is the same as the .*.swp
-file). Ofcourse, git can ignore these files or vim can store the swap files in a different location (see vim.wikia or this question at stackoverflow). But I like the .*.swp
-files showing up in git --status
when they contain unsaved changes, since it signals me that I'm committing files in a different state than what I think they are in.
How can I avoid the false positives of .*.swp
-files showing up in git --status
when the saved file is the same as the .*.swp
-file, while being able to see that file to commit are in a different state than the ones I'm editing with vim?
- Is it possible to only have
.*.swp
-files, when file on disk and file in vim are different? - Is there an other way to detect unsaved files?
Combining the comments of @elyashiv and @VanLaser results in a simpler method than detecting whether swap files imply unsaved files:
- do not let git ignore the .*.sw[po] files;
- when committing, if
git --status
reveals any.*.sw[po]
-files do a:wa
in vi; and, - add and commit.
:wa
to make sure there aren't any unsaved files.git commit
...