質問

I have a git repo which contains some XSLX files. I edit them with LibreOffice every once in a while. Sometimes LibreOffice won't remove the lock files ( ./folder/.~lock.filename.xslx#). This causes those files to be liested as new on every git status.

I would like git to ignore them. I tried the following in .gitignore but doesn't seem to work:

*.~lock*
.~lock*
*/.~lock*

Any ideas?

UPDATE

Also tried:

.~lock.*#

As seen in http://lists.freedesktop.org/archives/libreoffice-commits/2012-December/040253.html with no success.

役に立ちましたか?

解決

To test patterns for .gitignore,

git ls-files -ix '.~lock*'

To see if any cached aka staged aka tracked aka added files match ignore patterns (and so may have been added in error),

git ls-files -ic --exclude-standard

As @NevikRehnel pointed out, git won't ignore tracked files. To un-track a file,

git rm --cached path/to/it

which will take it out of the next commit, but the only way to take a file out of earlier history is a rewrite with e.g. git commit --amend if it was just the last commit, git rebase -i if you've got only a few to do or git filter-branch for bulk work. None of those actually alters the old history, they add new history and switch any current branch to refer to it. The old history is still there, and no other refs are moved.

他のヒント

Answer (as you discovered in your comments): adding *.~lock* inside the .gitignore file works just fine.

Also, if using Git for Windows, be sure to name your .gitignore file .gitignore, NOT .gitignore.txt, which is what Windows tries to force it to be if renaming or creating the file with Windows Explorer. To do this, save it using a text editor rather than trying to rename it in Windows Explorer (see more on this here).

If you accidentally have the .txt extension at the end it will NOT work and git will NOT read the file properly as a .gitignore file.

For more-detailed gitignore formatting notes, and to learn the syntax of how to specify files and folders to be ignored, see my comments and examples in my .gitignore file in my eRCaGuy_dotfiles repo.

If you tried the above solutions and the did not work, please check out this link, it helped me to solve it: excluding LibreOffice lock files

I actually ended up making making a .gitignore file, though originally I had been meaning to add them to the git "exclude" file. However I think the solution may work for that also.

Basically the idea is to close and restart libreOffice and "cd" out your git repo and back into it again for the changes to take effect.

I hope that helps someone else with this issue.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top