gitのstowディレクトリと非保存ファイル

gitのstowディレクトリと非保存ファイル

複数のファイルを1つのフォルダに保存します。このフォルダは設定フォルダであり、Git対応のStowバックアップから望ましくないその他の一時ファイルまたはシステム固有のファイルが含まれています。

Stowのgitリポジトリに意図的なファイルだけをコミットする最善の方法は何ですか?やや未使用ですかgit commit -a

挨拶

ベストアンサー1

*ファイルにのみ行を追加してください.gitignoregit 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

おすすめ記事