【发布时间】:2014-09-13 03:03:40
【问题描述】:
~/rails_projects/sample_app2 $ git branch
* master
~/rails_projects/sample_app2$ cat .gitignore
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'
# Ignore bundler config.
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
# Ignore other unneeded files.
database.yml
doc/
.*.s[a-w][a-z] #all swap files
.*.*.s[a-w][a-z]
.*.*.*.s[a-w][a-z]
*~
.project
.DS_Store
.idea
.secret
~/rails_projects/sample_app2$ touch .gitignore.swp
~/rails_projects/sample_app2$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 15 commits.
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore.swp
nothing added to commit but untracked files present (use "git add" to track)
~/rails_projects/sample_app2$ git add .
~/rails_projects/sample_app2$ git commit -m "Add swap file"
[master 364570c] Add swap file
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 .gitignore.swp
~/rails_projects/sample_app2$ git rm --cached .gitignore.swp
rm '.gitignore.swp'
~/rails_projects/sample_app2$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 16 commits.
#
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: .gitignore.swp
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore.swp
~/rails_projects/sample_app2$ git commit -m "Remove swap file"
[master 485217f] Remove swap file
0 files changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 .gitignore.swp
~/rails_projects/sample_app2$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 17 commits.
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore.swp
nothing added to commit but untracked files present (use "git add" to track)
~/rails_projects/sample_app2$ $ git add .
~/rails_projects/sample_app2$ git commit -m "Trying NOT to add swap files"
[master d743282] Trying NOT to add swap files
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 .gitignore.swp
不断地不断。当我这样做时,交换文件一直显示在未跟踪的文件列表中:
$ git status
因此,当我进行下一次提交时,交换文件会添加到 git 正在跟踪的文件中。如何让 git 忽略所有交换文件?
这似乎是一个常见的问题,应该有一个命令:
$ git ignore --all-swap-files
对其中一个 cmets 的回应:
~/rails_projects$ mkdir test_gitignore
~/rails_projects$ cd test_gitignore/
~/rails_projects/test_gitignore$ touch .gitignore
~/rails_projects/test_gitignore$ echo '.*.s[a-w][a-z]' > .gitignore
~/rails_projects/test_gitignore$ git init
Initialized empty Git repository in /Users/7stud/rails_projects/test_gitignore/.git/
~/rails_projects/test_gitignore$ touch file1.txt .file1.swp
~/rails_projects/test_gitignore$ mkdir subdir
~/rails_projects/test_gitignore$ touch subdir/.file2.swp
~/rails_projects/test_gitignore$ ls -al
total 8
drwxr-xr-x 7 7stud staff 238 Sep 14 10:41 .
drwxr-xr-x 19 7stud staff 646 Sep 14 10:38 ..
-rw-r--r-- 1 7stud staff 0 Sep 14 10:40 .file1.swp
drwxr-xr-x 10 7stud staff 340 Sep 14 10:40 .git
-rw-r--r-- 1 7stud staff 15 Sep 14 10:40 .gitignore
-rw-r--r-- 1 7stud staff 0 Sep 14 10:40 file1.txt
drwxr-xr-x 3 7stud staff 102 Sep 14 10:41 subdir
~/rails_projects/test_gitignore$ ls -al subdir
total 0
drwxr-xr-x 3 7stud staff 102 Sep 14 10:41 .
drwxr-xr-x 7 7stud staff 238 Sep 14 10:41 ..
-rw-r--r-- 1 7stud staff 0 Sep 14 10:41 .file2.swp
~/rails_projects/test_gitignore$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
# file1.txt
nothing added to commit but untracked files present (use "git add" to track)
~/rails_projects/test_gitignore$
【问题讨论】:
-
@meager,您花了多少时间阅读“重复”并将答案与我正在做的事情进行比较?
-
不长,很明显。
-
我已经回滚了这个问题,因为您已经对其进行了重大编辑(特别是,我的答案中建议的更改已被合并,其他内容也已更改)。请ask a new question - 别担心,问题是免费的,所以你可以(在合理的范围内)想问多少就问多少!
-
是的,我试图证明您的解决方案不起作用。
标签: git