Thu May 03 2018 • ☕️ 2 min read • you like my writing? Buy me a coffee
I had a very old Git branch (NewBranch) where I did some new development. In the meantime, the branch I originally branched from (OriginalBranch) was so different that I only wanted to copy out the changed files into a zip file. I found some funky Git one-liner commands that work on Linux/Mac, but I’m on good old Windows. I managed to do it as follows:
zip.exe
executable somewhere into your path. I always have a c:\bin
folder that is added to my path and I copy all tools into this directory. For zip.exe
I use Info-ZIP.git checkout NewBranch
. Make sure you get the latest files using git pull
. To see your list of branches and the currently checked out branch use the command git branch -a
.git merge-base OriginalBranch NewBranch
. This is a value that looks like be61fd84b7abe0b4735a21367ba70db68e5e4ef9
. If you want an overview of last commits execute the following command: git log --pretty=format:"%H - %an, %ar: %s"
. If you don’t like the long commit hashes you can also work with the abbreviated commit hashes. In this case use %h
instead.git diff --name-only be61fd84b7abe0b4735a21367ba70db68e5e4ef9 > diff-filelist.txt
. Where you use the commit hash of the commit from where you want to get the files from.more diff-filelist.txt | zip -@ files.zip
.Discuss on Twitter • Edit on GitHub
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. You are free to share and adapt this work for non-commercial purposes, provided you give appropriate credit, provide a link to the license, and indicate if changes were made. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/4.0/.
Personal blog by Serge van den Oever - als je maar lol hebt...
X: @svdoever
LinkedIn: Serge van den Oever - articles on LinkedIn
GitHub: svdoever
Technology Consultant @ Macaw
2021-2024 Sitecore Technology MVP