0

I am trying to checkout the modified files of a given commit. Or, checkout the modified files between two given commits (or two given branches) in to another branch.

Here is what I have done so far:

  1. Prepare a branch with the last last deployment "Depl_A"
  2. Switch to next deployment branch "Depl_B"
  3. Copy the modified files to branch "Depl_B"
  4. Created a blank branch using:
git clone --no-checkout <url>
git reset
git switch Depl_B_files
git add .
git commit -m "Prepare the branch with the modified files only for Deployment B" --allow-empty
git push origin --set-upstream Depl_B_files
  1. Following the instruction here, I am trying to bring (into Depl_B_files) the changed files only between Depl_A and Depl_B using a quick way, but could not apply that in my case since I am on Windows and using PowerShell.

My intention is to prepare a branch that has only the modified files so that I can use it as the source to deploy such files into the target platform. The files should be checked out from the deployment branch Depl_B_files and copied to the target folder on the machine using Jenkins and PowerShell.

Is there a better way? Can you help me achieve by objective?

tarekahf
  • 738
  • 1
  • 16
  • 42

1 Answers1

-1
  1. You use Git branches in extremely bad way and get dirty unreadable history as side-effect
  2. You ignore natural and easy way of getting list of changed files (for processing it later as you want), described on SO more than at least 2 times
  3. git diff and git archive are your best friends
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
  • I provided the hypothetical scenario to clarify what I am doing. I know that you can keep all deployments in one branch, and you can identify them with tags or commit IDs. Thank you for the answer, I am reviewing the details now. – tarekahf Jan 27 '22 at 14:46
  • I did the following using PowerShell: ```$filelist = @(git diff --diff-filter=ACMRTUXB --name-only hash1 hash2); $files = filelist -join " "; git archive --output=test_zip.zip hash2 $files``` but I am getting error `fatal: pathspec 'file1 file2 file2 ...' did not match any files.`. It seems that the single quote `'` is substituted with the command, so how to fix this problem? – tarekahf Jan 27 '22 at 15:39
  • as per this link https://en.wikibooks.org/wiki/Git/Advanced#:~:text=checkout%20tags/0.3.4-,Tags%20vs%20Branches,-%5Bedit%20%7C%20edit%20source it is very common to use different branches for different deployment targets. In my case, I was separating the deployment in a given target for clarification purposes. – tarekahf Jan 28 '22 at 17:17