0

the original commit contained 5 files:

a.txt
b.txt
c.txt
d.txt
e.txt

the next commit adds lines to the bottom of a.txt, deletes b.txt and uploads a new file f.txt. i.e.

a.txt    - additions from second commit
c.txt
d.txt
e.txt
f.txt    - new file from second commit

I would like to merge the commits, so that I accept changes a.txt, restore b.txt from the first commit and add f.txt from the latest commit. The repo should now look like:

a.txt    - additions from second commit
b.txt    - restored from first commit
c.txt
d.txt
e.txt
f.txt    - new file from second commit

I tried doing this with git rebase --root -i and left the original commit as "pick" and changed the second commit to "squash"

i.e.

pick commit1
squash commit2

but after rebase completes, I left with only commit2

Have I done something wrong, or is what I am asking not possible?

brucezepplin
  • 9,202
  • 26
  • 76
  • 129
  • I believe you can't pick a commit _partially_, like what you want to do for second commit. However, since I'm not an expert, I'm going to just check if anyone else has some sort of magic for doing that :) – Leonardo Alves Machado Oct 17 '17 at 11:14

1 Answers1

0

If you want to get the content of a given file(s) on a specific commit, simply run :

git checkout <commit> -- file1 [file2 ...]

It looks like you just need to do :

# get the version of b.txt from your previous commit :
git checkout <original commit> -- b.txt

# you will now see 'b.txt' as staged for commit :
git status

# create a new commit on top of the previous one :
git commit
LeGEC
  • 46,477
  • 5
  • 57
  • 104