Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a diff into a commit

Tags:

git

I had some unstaged changes in my repo. Output on the terminal:

--- a/app/something.java
+++ b/app/something.java
@@ -37,13 +37,17 @@ public class SomeController extends Controller{
                requestVo.setJobName("temp1");
                requestVo.setJobGroup("g1");
                requestVo.setJobInfo(JobInfo.INFO);
-               requestVo.setJobExecutionType(JobExecutionType.IMMEDIATE);
-               requestVo.setExecutionTime(new Date());
+               requestVo.setJobExecutionType(JobExecutionType.TIMED);
+               requestVo.setExecutionTime(getExecutionTime(3600*1000l));
                requestVo.setJobData("testing 123");
        }

+       private Date getExecutionTime(long delay) {
+               return new Date(System.currentTimeMillis() + delay);
+       }
+

...

Then I proceeded to git reset --hard HEAD, so I lost my changes. Is there any way to get back the changes? Or apply my changes from the terminal as a commit?

like image 211
TheChetan Avatar asked Jul 14 '26 12:07

TheChetan


1 Answers

If you still have the full output of your git diff, as the extract shown in your question suggests, you could try and:

  • select and copy-paste this git diff output in a file diff.patch.
  • apply that patch on your (reset) sources

That is:

git apply save.patch
# or
patch -p1 < save.patch

Note: git apply is preferred here, as git diff outputs a line for file renames, output which patch would ignore.

IF you don't have that full diff output... then previous answers/comments apply.

like image 70
VonC Avatar answered Jul 16 '26 08:07

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!