3

Some changes were made in git between hash A and hash B (the branch latest is in Z - thousands of commits later). I'd like to have the HEAD (my local one) point to hash A and have in my working directory all changes that were made between A and B.

Why? Because git diff is inconvenient and I'd rather work with the diff tool my IDE (IntelliJ IDEA) has. But for this I need to convince the IDE that I have changed files - hence the request.

Ran Biron
  • 6,317
  • 5
  • 37
  • 67

2 Answers2

5

I actually found a way:

git checkout <hash A>
git diff –patch <hash A> <hash B> > patch.patch
patch –p1 –N < patch.patch

A coworker also told me that I could've used

git checkout <hash A>
git merge --squash <hash B>

instead - but I didn't test it yet.

Ran Biron
  • 6,317
  • 5
  • 37
  • 67
  • I thought --squash had to do with combining multiple commits into a single one? That's doesn't exactly seem to have the same intention. – n00neimp0rtant Jan 23 '14 at 15:31
  • I actually wanted these squashed - same as if getting and applying a patch file for the diff between the two revisions. – Ran Biron Apr 30 '14 at 07:34
  • Okay, I see what you mean. I use git merge --squash all the time, but I usually squash changes between branches (not commits), and I never attempt to squash while having checked out anything other than HEAD. Just to avoid confusion, I like break out both the commit to be squashed and the commit to squash into out to their own branches. – n00neimp0rtant Apr 30 '14 at 14:01
1

You could:

  • git clone your local repo and reset it to hashB (see "Git clone particular version of remote repository")
  • git reset hashA within your local repo
  • empty its content and replace it: Git Plugin within IDEA will detect all the files added, missing or modified compared to current HEAD.
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250