git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
x1155665
V2EX  ›  git

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

  •  
  •   x1155665 · Aug 1, 2016 · 3319 views
    This topic created in 3596 days ago, the information mentioned may be changed or developed.
    环境:用 visual studio 写 c# 程序,用 git 同步。

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

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

    #ignore everything in this directory
    *
    # Except this dir
    !resourcexxx
    x1155665
        5
    x1155665  
    OP
       Aug 1, 2016
    @livelazily 靠谱!
    一些细节需要改一下:
    build result 文件夹里的 .gitignore 文件内容:

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

    解释:/ 对于表示文件夹是必须的,/ 后面加 * 是为了让 resourcexxx 的子文件里的文件也可以被包括。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1241 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 17:45 · PVG 01:45 · LAX 10:45 · JFK 13:45
    ♥ Do have faith in what you're doing.