在我的Serenity Java测试项目中,运行测试后,目标及其子目录“site”将填充数十个文件和目录,以显示报告和屏幕截图。当然,我不想将所有这些文件都提交到git存储库,甚至不希望看到它们被跟踪。我在我的.ignore文件中执行了此操作,该文件位于项目的顶层,并带有pom.xml,如图所示。
## Any un needed file any where in the project file structure.
*.class
*.tmp
*.jar
*.html
*.png
*.json
*.csv
*.DS_Store
# any eclipse project file.
.eclipse
.classpath
## All the folders underneath site folder
**/site
site/
site/*
## target folder at the top level of the project structue and paths and contents underneath it
target/
target/*
## target folder at any level of the project structue
**/target
/target
我仍然将文件记录为跟踪...
尝试使用以下逻辑:
!target/
target/site/*
这应该保留target/
文件夹,同时包括target/site
及其所有子文件夹。
这些文件之前有意外跟踪,但.gitignore
只适用于未跟踪的文件。所以添加一个.gitignore
“太晚了”会导致“不行”。
我不想将所有这些文件提交到git存储库,甚至不希望看到它们被跟踪。
你可以使用git filter-branch
来delete those files from the local history。
这解决了这个问题。从How to make Git "forget" about a file that was tracked but is now in .gitignore?的页面
第一:
git rm -r --cached。 git add。然后:
git commit -am“删除被忽略的文件”