1

Note, please be kindly to read my question first, befroe mark it as duplicate of how-can-you-undo-the-last-git-add.

Is there a git native way to get when the last git add . executed?

I recent do some coding in my ios project, and execute git add . without committing. Today I also do some coding in the project, and encountered a bug. I use git diff to check today's work, and not find any changes may lead to the bug.

I've test the ios app on my device last saturday. So I want to know when the last git add . was executed. If it was executed before last saturday, I can locate the bug in today's code.

LF00
  • 27,015
  • 29
  • 156
  • 295
  • 4
    Check the timestamp of `.git/index` if you haven't run any other commands that touch the file. Besides, `history` helps if you have configured something like https://www.cyberciti.biz/faq/unix-linux-bash-history-display-date-time/ – ElpieKay Jun 01 '17 at 09:21
  • 1
    The above comment is the only way I can think of. However, you should make small and frequent commits so that you can get a fine grained history to figure out such bugs. – Noufal Ibrahim Jun 01 '17 at 09:31
  • Use git reflog command to see the command history that will help you to know what command executed last. – danglingpointer Jun 01 '17 at 09:47
  • @LethalProgrammer I use `git reflog -all`, it not show command like `git add` – LF00 Jun 01 '17 at 09:54

4 Answers4

1

No, there isn't.

I suggest you commit code as soon as you can, and later you can easily merge multiple commit to a single commit using git-rebase

Zang MingJie
  • 5,164
  • 1
  • 14
  • 27
  • 1
    your solution won't give his difference of buggy code that OP has done. Please see what exactly he wants. – LuFFy Jun 01 '17 at 09:23
1

You need to Convert your added / staged Stated files (which you have done via git add .) to modified state using below command first :

git reset HEAD~1

And then use :

git diff

So that you can now see the Code difference.

For Reference :

When you start an empty repository and add a file, it will be in the untracked state,

When you use git add, Those files are now in staged state and ready to be committed inside the repository

To UNDO git add, just use git reset HEAD~1, so staged state files can be converted to untracked state.

LuFFy
  • 8,799
  • 10
  • 41
  • 59
0

A best effort way: to examine creation date of blob file.

This is definitely not the most simple way, but it may work even if we git add more than once.

When we git add a file, git may create a blob file in .git/objects:

(It may also reuse existing blobs without create new file)

# add a new file to index
$ echo gimme-a-new-blob > a
$ git add a

# list blob objects in stash
$ git ls-files --stage
...
100644 facd29e7e5ab3a8764cd7702daefc4f2b6515edd 0       a
...

# check the blob file, filenamed is based on sha1 of that blob
$ ls -l .git/fa/cd*
19 Jun  1 21:14 .git/objects/fa/cd29e7e5ab3a8764cd7702daefc4f2b6515edd

If we check all the blobs for files in index, the latest creation date may be what you want.

Jokester
  • 5,501
  • 3
  • 31
  • 39
0

You can check the .git/index or check the bash history. Refer to ElpieKay's comment.