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
6
votes
1 answer

Cannot use `git mergetool` with `git am` or `git apply` or `patch`

git mergetool is wonderful (in my case, I use kdiff3). However, it is not possible to use it to resolve conflicts from git am or git apply (or even with patch command). Indeed, mergetool need 3 files to work (base and both modified versions) while…
Jérôme Pouiller
  • 9,249
  • 5
  • 39
  • 47
6
votes
2 answers

find the first or last commit a patch applies to

Assuming a patch was created from a specific commit in the past, and no longer applies to HEAD. How can I find either the first or better the last commit in the history of HEAD, where this patch applies with "git apply" ? Maybe something with git…
donquixote
  • 4,877
  • 3
  • 31
  • 54
5
votes
2 answers

Is there any method to efficiently apply large git patches?

We received a large patch with about 17000 files modified. Its size is 5.2G. When applying the patch with git apply -3, it didn't finish after 12 hours. We split the patch into smaller patches per file and applied them one by one, so that at least…
ElpieKay
  • 27,194
  • 6
  • 32
  • 53
5
votes
3 answers

Git one-liner for applying a patch interactively

I have this patch file, it contains a bunch of modifications that I'd like to apply to a git branch. But I don't want to make one unique commit with all those modifications, instead I'd like to split it into 2 or 3 commits. I know I can achieve this…
arainone
  • 1,928
  • 17
  • 28
4
votes
0 answers

git apply patch exclude 2 files

How do you git apply patch but exclude 2 files? For 1 file or file pattern you could do --exclude flag. But what if I have 2 different files a.rb and b.rb I need to exclude but I have c.rb, d.rb, e.rb also in the patch which needs to be applied.
rubyprince
  • 17,559
  • 11
  • 64
  • 104
4
votes
1 answer

Understanding and trying to apply git patch for fuse filesystem

I have a fuse-based file system, in order to improve it I need to implement this approach https://lwn.net/Articles/674286/ I understand that i should git apply < patch >, the problem is that i don't understand exactly where this patch should be…
userfault
  • 199
  • 1
  • 10
3
votes
1 answer

git apply --reject vs git apply --3way

We have hundreds of repositories and receive patches regularly from the upstream. A job applies these patches with git apply --check . If there is no error, the patch is applied with git apply and the changes are committed. If any…
ElpieKay
  • 27,194
  • 6
  • 32
  • 53
3
votes
2 answers

Git merge file content outside of a repo (--no-index)

The git diff command (with the --no-index flag) works incredibly well to diff two files, irrespective of whether or not these two files are contained in a Git repo or not. Example $ git diff --no-index -- filea fileb // shows diff between filea and…
friederbluemle
  • 33,549
  • 14
  • 108
  • 109
3
votes
2 answers

Git stash apply - does git try to merge before applying?

Let's say I have a local repo and made some changes - some were added to the index while some were only tracked but left in the workspace without being added to index. If I were to stash the changes, keep working (after stashing) on the same branch…
caffein
  • 303
  • 1
  • 10
3
votes
1 answer

Ignore space difference in context line when applying git patch

I'm trying to apply patch generated from some git repository. Patch context line looks like this else if ( o is Item ) and in my code it looks like this else if (o is Item) When I apply patch $ git apply -v --check --directory=myroot…
Soteric
  • 3,070
  • 5
  • 24
  • 23
2
votes
1 answer

"git apply" gives error "does not match index" when a previous apply skips hunks

git version 2.19.0 I have two commits for file 'myfile' I am cherry picking from one branch to another branch. During the last patch apply, I get "error: mydir/myfile: does not match index". 1) I generate the two patch files commit1.patch (oldest)…
jimvfr
  • 353
  • 5
  • 10
2
votes
1 answer

How to fix one or more hunks were rejected in the patch you just applied error?

While applying patch in git, I am getting the below error if I have same files modified in working copy which were there in patch. One or more hunks were rejected in the patch you just applied, you will find the hunk in '.rej' files of the same…
Surendra Reddy
  • 219
  • 3
  • 10
2
votes
2 answers

Why the mergetool isn't opened when I use --3way on git apply?

Why I fail to use git apply with -3 option : $ git apply --3way /tmp/0001-my-patch.patch error: patch failed: a.h:9 Falling back to three-way merge... Applied patch to 'a.h' cleanly. error: patch failed: b.c:6 Falling back to three-way…
0x90
  • 39,472
  • 36
  • 165
  • 245
1
vote
1 answer

Why does git-diff produce trailing whitespaces by default on its own empty lines?

I became aware of this because a pre-commit config started checking for the trailing-whitespace condition (the generated diff in question is itself part of a repo so a git commit catches the condition of the whitespaces). I basically refer to all…
j riv
  • 3,593
  • 6
  • 39
  • 54
1
vote
1 answer

Add few files to Stash (Git)

currently I got a few modified files into my local branch: modified: commands/abc/Test.cs modified: common/des/Info.cs modified: common/pit/Abc.cs modified: services/Services123.cs I want to put to stash just first 3. How can I do that?
4est
  • 3,010
  • 6
  • 41
  • 63