Search code examples
gitgit-pullgit-diffgit-fetch

GIT download pull request files changed


I'm trying to just download the changed files in PULL REQUEST in GIT for deployment purpose.

Could you please help me figuring out the best way.

For now, develop is my default branch.

git clone https://mygitreposerver.net/EWE/mygitrepo.git

cd mygitrepo

git fetch origin pull/$n/head:pull_$n

git diff --name-only develop pull_$n

mkdir ../mygitrepo-modified

cp --parents $(git diff --name-only develop pull_$n) ../mygitrepo-modified

Replace $n with PR#.

This will give me the name of all changed files.

I doubt it's the efficient approach, and believe there should be some simple way of fetching only changed files from GIT PR.

Could you please help!!


Solution

  • You can use git archive to export your files. Adding to this, you can filter and export only the changed files. You should get a zip file with all your changed files.

    In your case:

    git archive -o update.zip pull_$n $(git diff --name-only develop pull_$n)
    

    You can also pipe to tar with:

    git diff --name-only develop pull_$n | xargs tar -czf ../update.tar.gz
    

    But as you can see, both solutions are pretty similar to what you are already doing.