V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
x1155665
V2EX  ›  git

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

  •  
  •   x1155665 · 2016-08-01 07:40:50 +08:00 · 2310 次点击
    这是一个创建于 2818 天前的主题,其中的信息可能已经有所发展或是发生改变。
    环境:用 visual studio 写 c# 程序,用 git 同步。

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

    或者是可以把这些所需的文件直接添加到 c# 项目里,然后 Build 的时候 VS 直接自动把文件复制到 Build result 文件夹里?
    5 条回复    2016-08-01 20:01:56 +08:00
    livelazily
        1
    livelazily  
       2016-08-01 08:39:05 +08:00
    至少你得把那些附件文件放到 Build result 的某个子目录下,然后 .gitignore 里使用
    !buildresult/resourcexxx
    来排除忽略
    如果是直接在 build result 下的话, 你就得一个一个加文件名排除
    wysnylc
        2
    wysnylc  
       2016-08-01 08:45:00 +08:00
    shell 脚本
    x1155665
        3
    x1155665  
    OP
       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
        4
    livelazily  
       2016-08-01 19:04:28 +08:00   ❤️ 1
    @x1155665 这样试试:
    工程根目录.gitignore 文件不忽略 buildresult ,
    buildresult 文件夹内再新建一个 .gitignore 文件, 内容:

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

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

    解释:/ 对于表示文件夹是必须的,/ 后面加 * 是为了让 resourcexxx 的子文件里的文件也可以被包括。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1008 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:31 · PVG 03:31 · LAX 12:31 · JFK 15:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.