Home > Enterprise >  How to get all new code between commits and save them to folder
How to get all new code between commits and save them to folder

Time:09-06

Due to legal issues I need to get all new code files between two distant commits (2 years of development). I need only whole new files, changes in existed files are not required. I am using Fork and I can see all new files, but I need all of them extracted to folder and I don't know how to do it. How to do it with git commands?

CodePudding user response:

https://superuser.com/questions/117626/find-recently-added-files-with-git

Other way I can think of, without any git magic:

Checkout commit A, copy your project to some folder. Checkout commit B.

Now find the files that exist in B, but not in A. These files have been added since A.

CodePudding user response:

To list all files that are new in commitB with respect to commitA :

git diff --name-only --no-renames --diff-filter=A <commitA> <commitB>

To make a tar archive out of those :

# the active commit must be commitB,
# 'git status' must indicate a clean worktree (no changes to any versioned files)

git diff --name-only ... | xargs tar -cf newfiles.tar

# if you want it gzipped :
git diff --name-only ... | xargs tar -czf newfiles.tgz

CodePudding user response:

Do a soft git reset to the earliest commit using git reset HEAD~<number of commits to go back>

This will reset all the changes and bring the codebase to the earliest commit. You shoudl be able to see all changes including modifications to existing files and new files.

Now do a git checkout . and that will remove all changes to the files that existed at that commit and the later commits. You will be left only with files that did not exist at the earliest commit.

Additionally if you want to remove those new files also, you will have to do a git clean -f ..

  •  Tags:  
  • git
  • Related