I had a script that, for each changed_file in
"git diff --name-only master..origin/master"
the diff for that file is applied like the following:
git diff master..origin/master file_name | git apply.
For any newly creately files (files in origin master but not originally in master), I got the following errors:
fatal: ambiguous argument 'my_file_name': unknown revision or path not in the working tree.
error: unrecognized input
Upon searching on SO, I found the following information on the intent-to-add flag of git add: What does git add --intent-to-add or -N do and when should it be used?
So I tried the following: for each file I'm about to get a diff of between origin/master and master, if that file doesn't currently exist in master (local), then I call git add with --intent-to-add flag prior to calling git diff with that filename and applying the diff.
if ! ls "$changed_file" 1> /dev/null 2>&1; then
echo adding new file "$changed_file"
echo foo > "$changed_file"
git add --intent-to-add "$changed_file"
fi
git diff master..origin/master "$changed_file" | git apply
With this, I'm getting the following error when trying to do the git apply (last line), saying the file already exists in working directory:
error: tests/new_file: already exists in working directory
When I tried removing the dummy file creation part, like the following, it also didn't work.
if ! ls "$changed_file" 1> /dev/null 2>&1; then
echo adding new file "$changed_file"
git add --intent-to-add "$changed_file"
fi
with the error message being the same as before:
fatal: ambiguous argument 'my_file_name': unknown revision or path not in the working tree.
error: unrecognized input
Does anyone know what's going on, and how I can fix this? (get and apply diff of NEW remote file)