0

i want to commit my changes, but git hangout, when i run

git add .

i rerun it using -v option, then i get

add 'dev/less/module/basic-structure/eo-featured.less'
add 'dev/less/module/page-content/content/.eo-cv.less.swo'

am using vim, that's why i guess that .swo file, i don't know what that is, but i don't need it, so i run:

git rm dev/less/module/page-content/content/.eo-cv.less.swo

the result was

fatal: pathspec 'dev/less/module/page-content/content/.eo-cv.less.swo' did not match any files

any ideas ?

Oussama Elgoumri
  • 609
  • 1
  • 5
  • 15
  • What is the question? Are you asking why `git add .` hangs, or are you asking what's going on with that `.swo` file? – jub0bs Nov 21 '14 at 16:43
  • 1
    You may want to check out [Fugitive](https://github.com/tpope/vim-fugitive) for your Vim + git needs. See the following [Vimcasts](http://vimcasts.org/) episodes about it: [The Fugitive Series - a retrospective](http://vimcasts.org/blog/2011/05/the-fugitive-series/) – Peter Rincker Nov 21 '14 at 16:47
  • @jubobs am asking both, why git is hang, for the file, is just a hint. – Oussama Elgoumri Nov 21 '14 at 17:25

4 Answers4

4

your swo file is very likely created by vim, so called swap file. In vim, you can :h swap to check details.

If you don't want vim to generate swap file, you can set the option:

set noswf

You got error msg when you tried to "delete" the swo file, because, the file hasn't been tracked by git yet, you used git rm .... You should use rm ...file to remove it. In fact, if you start/close your vim normally, you don't have to manually remove the swap file. Vim will delete it after you quit vim.

So, you can either set the above option, avoid createing swap file. or add an entry in .gitignore to let git ignore those files.

Kent
  • 189,393
  • 32
  • 233
  • 301
  • the file does not exists at all, i don't now from where git found it ? – Oussama Elgoumri Nov 21 '14 at 17:19
  • if .swo is a swap file, then what is .swp file? – Oussama Elgoumri Nov 21 '14 at 17:26
  • 1
    You ran git with your file opened in vim – Kent Nov 21 '14 at 17:33
  • *add an entry in `.gitignore`*. [Even better](http://stackoverflow.com/a/26851996/2541573): instead of adding `*.swo` and `*.swp` entries in the project's `.gitignore`, add them to a global (i.e. user-level) `.gitignore`. Contributors to the project who do not use Vim have no need for those entries in the project's `.gitignore`, and it's best to keep the latter lean and tidy. – jub0bs Nov 21 '14 at 17:52
2

If the file was never committed, git rm won't work.

Running git status will show you how to properly unstage this file:

$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
        new file:   dev/less/module/basic-structure/eo-featured.less
        new file:   dev/less/module/page-content/content/.eo-cv.less.swo

So git reset HEAD dev/less/module/page-content/content/.eo-cv.less.swo should unstage the file.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • 1
    *If the file was never committed, `git rm` won't work.* True, but that's not what's happening here. The error message you get in the case you describe is `error: the following file has changes staged in the index: ...`, which is different from the error message the OP is reporting. – jub0bs Nov 21 '14 at 17:49
1

The .swo file isn't tracked by git (unless you already added it in the past), this is why you can't use git rm (which only tells git to stop tracking the files).

You just don't want to stage it when using git add, and you have two ways to do that:

  1. Giving only the files you really want to stage to git add (instead of of .)
  2. Writing *.swo to your .gitignore file (which you can create if it doesn't exist).
Dettorer
  • 1,247
  • 1
  • 8
  • 26
  • i've copied vim.gitignore to .gitignore, but it does not contain .*.swo, any idea why this extension was not added by default to vim.gitignore file ? – Oussama Elgoumri Nov 21 '14 at 17:22
1

i solved this problem, which i think is an issue, because using -v option, was not provide me with the information i needed.

the problem was because of a huge file, called ctags, that git was trying to add to the staged area, and its taking too long.

i added it to .gitignore along with .*.swo files, and the problem was solved.

so if git hangout just check if you have a huge file in your directory.

Oussama Elgoumri
  • 609
  • 1
  • 5
  • 15