如何在不同步 Build Result 的情况下同步与 Build result 同文件夹的文件?

2016-08-01 07:40:50 +08:00
 x1155665
环境:用 visual studio 写 c# 程序,用 git 同步。

程序运行需要使用试用一些附件的文件(比如图片文件),我把这些附加文件放在 build result 的文件夹里,这样方便程序直接调用。但是 build result 默认是不被同步的,整个文件夹被 git 排除了。有没有什么办法可以同步这些附加文件而不同步临时的 Build result 文件?(不要一个一个排除临时文件后缀的办法。。)

或者是可以把这些所需的文件直接添加到 c# 项目里,然后 Build 的时候 VS 直接自动把文件复制到 Build result 文件夹里?
2319 次点击
所在节点    git
5 条回复
livelazily
2016-08-01 08:39:05 +08:00
至少你得把那些附件文件放到 Build result 的某个子目录下,然后 .gitignore 里使用
!buildresult/resourcexxx
来排除忽略
如果是直接在 build result 下的话, 你就得一个一个加文件名排除
wysnylc
2016-08-01 08:45:00 +08:00
shell 脚本
x1155665
2016-08-01 15:45:17 +08:00
@livelazily 不能这么做。。因为母文件夹 build result 已经被排除了。

“ An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn ’ t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined. Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, "\!important!.txt" ”
livelazily
2016-08-01 19:04:28 +08:00
@x1155665 这样试试:
工程根目录.gitignore 文件不忽略 buildresult ,
buildresult 文件夹内再新建一个 .gitignore 文件, 内容:

#ignore everything in this directory
*
# Except this dir
!resourcexxx
x1155665
2016-08-01 20:01:56 +08:00
@livelazily 靠谱!
一些细节需要改一下:
build result 文件夹里的 .gitignore 文件内容:

#ignore everything in this directory
*
# Except this dir
!resourcexxx/*

解释:/ 对于表示文件夹是必须的,/ 后面加 * 是为了让 resourcexxx 的子文件里的文件也可以被包括。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/296229

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX