簡體   English   中英

.gitignore不忽略tfvars和.terraform目錄

[英].gitignore not ignore tfvars and .terraform directory

看來我的.gitignore不符合預期。

$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   .gitignore
        new file:   win_2016_datacentre_vm/.terraform/plugins/linux_amd64/lock.json
        new file:   win_2016_datacentre_vm/.terraform/plugins/linux_amd64/terraform-provider-azurerm_v1.16.0_x4
        new file:   win_2016_datacentre_vm/aos-1.tfvars
        new file:   win_2016_datacentre_vm/aos-1.v1/.terraform/plugins/linux_amd64/lock.json
        new file:   win_2016_datacentre_vm/aos-1.v1/.terraform/plugins/linux_amd64/terraform-provider-azurerm_v1.16.0_x4
        new file:   win_2016_datacentre_vm/aos-1.v1/aos-1.plan
        new file:   win_2016_datacentre_vm/aos-1.v1/aos-1.tf
        new file:   win_2016_datacentre_vm/aos-1.v1/aos-1.tfvars
        new file:   win_2016_datacentre_vm/aos-1.v1/terraform.tfstate
        new file:   win_2016_datacentre_vm/aos-1.v1/terraform.tfstate.backup


Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   .gitignore

$ cat .gitignore
# Local terraform directories
docker/*
terraform-getting-started/*
terraform-getting-started.zip
**/.terraform/**
*/**/.tfvars
*.tfstate

令我感到奇怪的是,即使我添加了.terraform,*。tfvars和* .tfstate,為什么仍以git狀態報告它們?

還應該將tfstate提交到存儲庫嗎?

非常感謝您的協助。

謝謝

為了稍微擴展一下zerkms的評論 ,此行:

Changes to be committed:

告訴您(和我們)您已經告訴Git: 請包括以下文件

文件名.gitignore頗具誤導性。 現在看來似乎是為文件名的文件,或模式的名單,那混帳不應該包括,但它不是;相反,那就是如果他們不是已經存在的Git應該不會自動添加文件名列表(但他們已經在那里),並且不應該認為你應該添加

更長,但很高興知道

Git的模型是Git根據Git調用的人/哪個部分,從Git調用的內容( 索引暫存區緩存)構建新的提交。 我所知道的對索引的最佳簡短描述是,它是Git構建下一個提交 (或在本例中是第一個提交)的地方。

當你第一次檢查出存在的一些承諾,你還不能,因為根本就沒有什么,但在當你使用未來一段時間內git checkoutgit clone運行git checkout你,Git會指數填寫提交,然后使用從提交中提取的索引內容來填充工作樹。 現在,索引副本和工作樹副本都匹配,並且它們都匹配從提交中取出的文件。

當您有一個充滿文件的工作樹並更改了其中一些文件時,可以運行git add將現有的工作樹文件重新復制回索引中,以使它們為下一次提交做好准備。 現在,索引副本和工作樹副本再次匹配,並且兩者都仍在提交中的文件不同 (或者,如果該文件是全新的,則它現在不在索引中了。)

當您進行提交時,Git會凍結索引中的副本,並將其放入提交中。 索引中的所有內容現在都在新提交中,現在是當前提交。 因此,現在索引與提交匹配,就好像您剛剛簽出該提交一樣。 如果所有索引文件都與所有工作樹文件匹配,則每個文件的所有三個副本都將匹配,就像您第一次簽出提交時一樣。

從索引中刪除一個文件,使用git rm :這會從索引工作樹將其刪除。 要僅將其從索引中刪除並保留在工作樹中,請改用git rm --cached 請注意:如果文件在某些​​現有提交中,並且從索引中將其刪除,則該文件將不在您進行的提交中,但仍將是現有提交。 檢出其中之一將(或至少可以)使用git rm --cached覆蓋您故意留下的工作樹文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM