我将几个文件存放在一个文件夹中。该文件夹是一个配置文件夹,并且包含其他临时文件或系统特定文件,我不希望这些文件出现在我的 Git 支持的 Stow 备份中。
仅在 Stow 的 git 存储库中提交有意文件的最佳方法是什么?是不是或多或少没有使用git commit -a
?
问候
答案1
*
在文件中添加一行 with just .gitignore
。 git add
然后,只有当您使用该选项强制添加文件或目录时,才会添加文件或目录-f
。
例如:
$ mkdir /tmp/git-test
$ cd /tmp/git-test
$ git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /tmp/git-test/.git/
$ date > file1.txt
$ date > file2.txt
$ date > file3.txt
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
file1.txt
file2.txt
file3.txt
nothing added to commit but untracked files present (use "git add" to track)
$ echo '*' > .gitignore
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
$ git add file1.txt
The following paths are ignored by one of your .gitignore files:
file1.txt
hint: Use -f if you really want to add them.
hint: Turn this message off by running
hint: "git config advice.addIgnoredFile false"
$ git add -f file1.txt
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: file1.txt
$ git commit -m 'initial commit'
[master (root-commit) 2007ca3] initial commit
1 file changed, 1 insertion(+)
create mode 100644 file1.txt
$ date >> file1.txt
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: file1.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git commit -m '2nd commit' .
[master dba5fea] 2nd commit
1 file changed, 1 insertion(+)
$ git commit -m '3rd commit' *
error: pathspec 'file2.txt' did not match any file(s) known to git
error: pathspec 'file3.txt' did not match any file(s) known to git
$ date >> file1.txt
$ git commit -a -m '3rd commit'
[master e679fde] 3rd commit
1 file changed, 1 insertion(+)
$ mkdir foo
$ date >> foo/bar.txt
$ git status
On branch master
nothing to commit, working tree clean
$ git add -f foo
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: foo/bar.txt
$ git commit -a -m '4th commit'
[master 4048a90] 4th commit
1 file changed, 1 insertion(+)
create mode 100644 foo/bar.txt