Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
679 views
in Technique[技术] by (71.8m points)

vim - git creates files ending in ~?

Just started using git on my mac. I have one file in my repository called README. When I change it, git puts another file in the directory called README~ containing the previous version.

  1. Is it git doing this?
  2. Why is git doing this?
  3. How can I stop git doing this? (don't just want to add it to .gitignore, but I guess I could do that but I'd rather understand why I'm getting these files in the first place..)

(It's hard to search for an answer on Google cos of trying to search on "~")

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The tilde suffix on file names is usually used by editors (Emacs, Vim in some modes/versions) on backup copies of files you edit. At one time on Mac, Vim seemed to create backups for me; it doesn't any more, but I'm not sure now whether that's because I tweaked a setting somewhere or whether vim changed its behaviour.

I have not seen git add tilde suffixes to file names (either on a Mac where I work mainly, or anywhere else).

To stop git wanting to add the files, add a line containing just *~ to .gitignore.

Vim has (at least) three settings related to this:

nobackup
  backupcopy=auto
  backupext=~

My ':set all' shows the values above. Yours probably shows 'backup' rather than 'nobackup'.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...