ian
ian

Reputation: 12251

Git: how to see the changes for a file before push - not the diff, the final version

The context is, I've added some changes to a file using add -p and because of the way git was presenting the patches I can't be sure the result will be good. I want to see the file as if I'd committed, then pushed, and then someone else had pulled the file. Not the diff, I just want to see that final version of the file. I need to preserve my changes to the current file, any clobbering of that file would be vexing to say the least!

The only way I can think to do this is:

The main problem I have with a rollback is that I'll have to go through all the adding again. Squashing could be problematic too - it would just be easier if I could see the staged file in one piece before commit. Is this possible, or is there another "easy" way? (nothing arcane please, Git is already too arcane for me to get knee deep in just for this!)

Upvotes: 1

Views: 346

Answers (2)

vratojr
vratojr

Reputation: 845

If you are not obliged to go through the command line you can use 'git gui' that lets you stage the hunks of code you prefer while giving you the preview of the final result.

Upvotes: 1

Dietrich Epp
Dietrich Epp

Reputation: 213847

You can use git cat-file.

$ git add -p my_file.c
$ git cat-file blob HEAD:my_file.c

Note that the path is relative to the top of the repository.

Upvotes: 4

Related Questions