Questions tagged [git-apply]

Git command that applies a patch to files and/or to the index.

This command reads the supplied diff output (i.e. "a patch") and applies it to files.

With the --index option the patch is also applied to the index, and with the --cached option the patch is only applied to the index. Without these options, the command applies the patch only to files, and does not require them to be in a git repository.

This command applies the patch but does not create a commit. Use git-am to create commits from patches generated by git-format-patch and/or received by email.

47 questions
275
votes
6 answers

Create patch or diff file from git repository and apply it to another different git repository

I work on WordPress based project and I want to patch my project at each new release version of WP. For this, I want generate a patch between two commits or tags. For example, in my repo /www/WP I do this: $ git patch-format com1..com2 --stdout >…
zatamine
  • 3,458
  • 3
  • 25
  • 33
171
votes
5 answers

When applying a patch is there any way to resolve conflicts?

I am on windows. For various reasons we have multiple git instances of different svn branches. Many times I want to fix an issue in repository A, generate a patch, and apply it to repository B. This works fine except if there are conflicts. When…
Kenoyer130
  • 6,874
  • 9
  • 51
  • 73
25
votes
3 answers

How do I apply rejected hunks after fixing them?

I'm trying to apply a patch to a file using git apply. The overall patch failed, so I used git apply --reject. Inspecting the generated .rej file showed me what's wrong, now I fixed the problem in the .rej file. But trying to apply the .rej file…
eckes
  • 64,417
  • 29
  • 168
  • 201
14
votes
2 answers

git apply error no such file or directory

I have two sepearate git repos: A and B. Some repository B files are already present in a subfolder of project A. My goal is to create patches for repo B and then applying them to the subfolder within repo A to conserve history of repo B while…
sid99
  • 141
  • 1
  • 1
  • 3
14
votes
6 answers

Error "git diff header lacks filename information when removing 1 leading pathname component " when executing git apply

I created a diff file by a command: git --no-pager diff --no-index --stat pathA pathB >\diff.log Nextly, I executed a command: git apply --index --ignore-space-change --ignore-whitespace \diff.log During the execution I encountered an…
krawat10
  • 181
  • 1
  • 10
11
votes
2 answers

check if git apply was already applied

This question is about git apply Is there a way to distinguish between: it failed because... ... the patch is already applied ... the source code is really different The directory i work in is not a git directory, therefore i can't use git log or…
ataraxis
  • 1,257
  • 1
  • 15
  • 30
10
votes
1 answer

How to git-apply a git word diff

I needed to edit a messy commit commit that only changed a word in a few subsequent rows, keeping some of those changes and removing others. The changes were easy to see in git diff --word-diff, and in that format I could easily edit the hunks to do…
Anaphory
  • 6,045
  • 4
  • 37
  • 68
10
votes
3 answers

How to prepare and apply multiple patches for the last N commits in git

I need to create a patch file for the last N commits and apply them as separate commits to another branch. For N=3 I assume I have to do this: git diff HEAD~3 HEAD~2 >> diff1 git diff HEAD~2 HEAD~1 >> diff2 git diff HEAD~1 HEAD >> diff3 and…
B Faley
  • 17,120
  • 43
  • 133
  • 223
9
votes
2 answers

magento 2 vendor git diff & apply patch

Mainly, this question is specific to git with Magento 2. I have a working Magento 2 project and I have installed an extension using github repo - https://github.com/Adyen/adyen-magento2. In my current situation, I have to debug that extension and…
Kamal Joshi
  • 1,298
  • 3
  • 25
  • 45
9
votes
1 answer

Difference between the diff command 'diff -b' and 'git diff'

I have always used diff -b to make patches even when working on a git repo. What is the difference between the two, does git diff / git format-patch also internally makes use of the linux/unix diff command? (I know the difference between git…
brokenfoot
  • 11,083
  • 10
  • 59
  • 80
7
votes
2 answers

How to make a patch ignore the file index using "git apply"?

I'm trying to apply a .patch file to my source, but it fails because my file index (10655) is older than the patch index (10755). Now I know that I can just modify the patch's file index but I would like to know if there is any way using git to…
Placeholder
  • 4,651
  • 6
  • 33
  • 35
7
votes
0 answers

`git apply --ignore-whitespace` is broken

According to the official git docs: git apply --ignore-space-change, --ignore-whitespace When applying a patch, ignore changes in whitespace in context lines if necessary. Context lines will preserve their whitespace, and they will…
jdunk
  • 2,738
  • 2
  • 17
  • 25
6
votes
2 answers

how to see the file which would be committed

I have modified a file (or some files) in my directory, and I've used git add to stage some of the changes lines from the file, but not all the changed line. I can use git diff --staged my-file to see the diff of what's changed. git diff --staged…
Jim Newton
  • 594
  • 3
  • 16
6
votes
1 answer

Can you make git apply with a dry run?

I would like to know, which files would be written when applying a .patch file with git apply. Is there a way to apply a .patch file in git with a dry run?
TheDarkTron
  • 304
  • 4
  • 13
6
votes
2 answers

How to 'git-am' apply a patch created with 'git-format-patch --no-prefix'?

I have a reason¹ to create my git commits as patch files using git-format-patch with the --no-prefix option. This option changes the patch output to not add the git-diff-specific prefixes a/ / b/ in file paths in the patch files. It allows tools…
gertvdijk
  • 24,056
  • 6
  • 41
  • 67
1
2 3 4