Creating git diff for new files without a trace

Often I find that I want to split the working state in the git tree without commits / branches using git diff and pastebins, email, etc. This works great when all changes are modifications to files already tracked, but not when there are new files. I can use git add -N to add an empty tracked file to diff, but this is problematic if I am going to do other things before the changes in question (or if the changes in the question are just trash, I want to throw away). Is there an easy way to get diff to add new files included in git diff without changing their status in the repository? So far I have an ugly script:

 for i in " $@ " ; do diff -u /dev/null "$i" | sed -e ' s@ ^+++ @+++ b/@ ; done 

Is this the best way?

I am not completely opposed to alternative solutions that change the state of git until it easily returns to the state exactly before the change (for example, with various modified files, some changes, etc.)

+6
source share
1 answer

You can export unknown, modified, or deleted files to an archive such as .tar.gz and send them to your colleagues. You can try the following:

  • Export Modified, Moved, and Deleted Files

    tar zvcf ~/new-files-cache.tar.gz `git diff --name-only --diff-filter=ACMRT`

  • Export unprocessed (new), modified, and deleted files

    tar zvcf ~/new-files-cache.tar.gz ` git status --short | sed 's/^ *[^ ]* \(.*\)/\1/g' `

I found solutions here: https://cmanios.wordpress.com/2014/04/12/export-untracked-modified-moved-and-deleted-files-from-a-git-repository-to-archive/

0
source

Source: https://habr.com/ru/post/985427/


All Articles