1

TeamCity で実行される Ant ビルド スクリプト内でこれを使用します。

4

2 に答える 2

1

これは私がやったことであり、かなりうまく機能します。プロジェクト内のマークダウン (拡張子 .md) ファイルのみを編集する必要がありました。

#clone as usual
git clone https://github.com/username/repo.git myrepo

#change into the myrepo directory that was just created 
cd myrepo

#turn off tracking for everything
#this allows us to start pruning our working directory without the index 
#being effected, leaving us only with the files that we want to work on
git ls-files | tr '\n' '\0' | xargs -0 git update-index --assume-unchanged

#turn on tracking for only the files that you want, editing the grep pattern
# as needed
#here I'm only going to track markdown files with a *.md extension
#notice the '--no-assume-unchanged' flag
git ls-files | grep \\.md | tr '\n' '\0' | xargs -0 git update-index --no-assume-unchanged

#delete everything in the directory that you don't want by reversing 
#the grep pattern and adding a 'rm -rf' command
git ls-files | grep -v \\.md | tr '\n' '\0' | xargs -0 rm -rf

#delete empty directories (optional)
#run the following command. you'll receive a lot of 'no such file or 
#directory' messages. run the command again until you 
#no longer receive such messages.you'll need to do this several times depending on the depth of your directory structure. perfect place for a while loop if your scripting this
find . -type d -empty -exec rm -rf {} \;

#list the file paths that are left to verify everything went as expected
find -type f | grep -v .git

#run a git status to make sure the index doesn't show anything being deleted
    git status

君は見るべきだ:

# On branch master
nothing to commit, working directory clean

終わり!

これで、すべてをチェックアウトしたかのように、これらのファイルを操作できます。たとえば、リモートへのプルとプッシュを実行すると、チェックアウトしたファイルのみが更新され、残りは削除されません。

于 2014-05-26T02:29:00.263 に答える
1

(「チェックアウト」とは、git 用語で「クローン」を意味すると仮定します。つまり、現在、リポジトリのコピーがなく、リモート リポジトリからいくつかのファイルを取得する必要があります。)

短い答えは、できないということです。

いくつかの制限はありますが、 git で浅いクローンを作成することはできますが (最新のいくつかのバージョンのみを取得する)、狭いクローンを簡単に作成することはできません(1 つのサブディレクトリなど、リポジトリの一部のみを取得するか、特定のバージョンに一致するファイルのみを取得する)。基準)。

ある意味では、これは実際には分散バージョン管理システムとしての git の機能です。リポジトリを複製すると、完全な履歴、すべてのブランチ、およびコードで完全に作業するために必要なすべてのものを持っていることがわかります。スタンドアロン。

もちろん、これにはさまざまな方法があります。たとえば、次のようになります。

  1. git archive --remote=<repo>リモートリポジトリの tar アーカイブを取得し、それをパイプするために使用できますtar -x --wildcards --no-anchored '*.whatever'
  2. 完全なリポジトリをローカルの別の場所にクローンし、ビルド スクリプトでそれを更新して、必要なファイルだけをコピーするだけです。
  3. などなど
于 2011-08-18T09:48:27.540 に答える