3

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?

TheChetan
  • 4,440
  • 3
  • 32
  • 41
  • 2
    If you didn't backup your working directory anywhere, and you really did a hard reset to your branch, then your changes may be lost. Options include falling back on your editor or IDE (e.g. IntelliJ or Sublime Text), which might have saved the previous local version, or making use of some other local backup. – Tim Biegeleisen Jan 29 '19 at 05:48

2 Answers2

6

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

git reset --hard discards your unstaged work and take your head to the previous commit. After running this command, git have no record of your changes. You have to use some other way but git can't help you here.

Gaurav Neema
  • 146
  • 1
  • 1
  • 12