History or log of commands executed in Git

Git

Git Problem Overview


Is there a way I can keep track of commands I used in Git under Windows? I want to view all the commands that I have applied on my repository.

I want to be able to go back through the command history and figure out the command that caused the problem if one occurred.

Seeing the history of commits would be one thing, but for keeping a history of other actions such as creating a branch or adding a remote, are these tracked?

Git Solutions


Solution 1 - Git

You can see the history with git-reflog (example here):

git reflog

Solution 2 - Git

A log of your commands may be available in your shell history.

history

If seeing the list of executed commands fly by isn't for you, export the list into a file.

history > path/to/file

You can restrict the exported dump to only show commands with "git" in them by piping it with grep

history | grep "git " > path/to/file

The history may contain lines formatted as such

518  git status -s
519  git commit -am "injects sriracha to all toppings, as required"

Using the number you can re-execute the command with an exclamation mark

$ !518
git status -s

Solution 3 - Git

If you are using CentOS or another Linux flavour then just do Ctrl+R at the prompt and type git.

If you keep hitting Ctrl+R this will do a reverse search through your history for commands that start with git

Solution 4 - Git

Type history in your terminal. It's not technically git, but I think it is what you want.

Solution 5 - Git

If you use Windows PowerShell, you could type "git" and the press F8. Continue to press F8 to cycle through all your git commands.

Or, if you use cygwin, you could do the same thing with ^R.

Solution 6 - Git

I found out that in my version of git bash "2.24.0.windows.2" in my "home" folder under windows users, there will be a file called ".bash-history" with no file extension in that folder. It's only created after you exit from bash.

Here's my workflow:

  1. before exiting bash type "history >> history.txt" [ENTER]
  2. exit the bash prompt
  3. hold Win+R to open the Run command box
  4. enter shell:profile
  5. open "history.txt" to confirm that my text was added
  6. On a new line press [F5] to enter a timestamp
  7. save and close the history textfile
  8. Delete the ".bash-history" file so the next session will create a new history

If you really want points I guess you could make a batch file to do all this but this is good enough for me. Hope it helps someone.

Solution 7 - Git

git will show changes in commits that affect the index, such as git rm. It does not store a log of all git commands you execute.

However, a large number of git commands affect the index in some way, such as creating a new branch. These changes will show up in the commit history, which you can view with git log.

However, there are destructive changes that git can't track, such as git reset.

So, to answer your question, git does not store an absolute history of git commands you've executed in a repository. However, it is often possible to interpolate what command you've executed via the commit history.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnilMoBileView Question on Stackoverflow
Solution 1 - GitjweyrichView Answer on Stackoverflow
Solution 2 - GitrandomView Answer on Stackoverflow
Solution 3 - GitcrmpiccoView Answer on Stackoverflow
Solution 4 - GitScottyBladesView Answer on Stackoverflow
Solution 5 - GitmambokingView Answer on Stackoverflow
Solution 6 - Gituser65795View Answer on Stackoverflow
Solution 7 - GitAlexView Answer on Stackoverflow