在 Git 中执行的命令的历史或日志
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7435452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
History or log of commands executed in Git
提问by nilMoBile
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.
有没有办法可以跟踪我在 Windows 下的 Git 中使用的命令?我想查看我在我的存储库中应用的所有命令。
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?
查看提交的历史记录是一回事,但是为了保留其他操作的历史记录,例如创建分支或添加远程,这些是否被跟踪?
采纳答案by Alex
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.
git 将显示影响索引的提交中的更改,例如git rm
. 它不会存储您执行的所有 git 命令的日志。
However, a large number of git commands affect the index in someway, such as creating a new branch. These changes will show up in the commit history, which you can view with git log
.
但是,大量的 git 命令会以某种方式影响索引,例如创建新分支。这些更改将显示在提交历史记录中,您可以使用git log
.
However, there are destructive changes that git can't track, such as git reset
.
但是,有一些 git 无法跟踪的破坏性更改,例如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.
因此,为了回答您的问题,git 不会存储git
您在存储库中执行的命令的绝对历史记录。但是,通常可以通过提交历史插入您执行的命令。
回答by jweyrich
回答by random
A log of your commands may be available in your shell history.
您的命令日志可能会在您的 shell 历史记录中可用。
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
您可以通过使用 grep 管道将导出的转储限制为仅显示其中包含“git”的命令
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
回答by crmpicco
If you are using CentOS or another Linux flavour then just do Ctrl
+R
at the prompt and type git
.
如果您使用的是 CentOS 或其他 Linux 风格,那么只需在提示符处执行Ctrl
+R
并输入git
.
If you keep hitting Ctrl
+R
this will do a reverse search through your history for commands that start with git
如果您继续按Ctrl
+R
这将在您的历史记录中反向搜索以开头的命令git
回答by ScottyBlades
Type history
in your terminal.
It's not technically git, but I think it is what you want.
输入history
您的终端。从技术上讲,这不是 git,但我认为这是您想要的。
回答by mamboking
If you use Windows PowerShell, you could type "git" and the press F8. Continue to press F8 to cycle through all your git commands.
如果您使用 Windows PowerShell,则可以键入“git”并按 F8。继续按 F8 循环浏览所有 git 命令。
Or, if you use cygwin, you could do the same thing with ^R.
或者,如果你使用 cygwin,你可以用 ^R 做同样的事情。
回答by user65795
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.
我发现在我的 git bash "2.24.0.windows.2" 版本中,在 Windows 用户下的“home”文件夹中,将有一个名为“.bash-history”的文件,该文件夹中没有文件扩展名。它仅在您退出 bash 后创建。
Here's my workflow:
这是我的工作流程:
- before exiting bash type "history >> history.txt" [ENTER]
- exit the bash prompt
- hold Win+R to open the Run command box
- enter shell:profile
- open "history.txt" to confirm that my text was added
- On a new line press [F5] to enter a timestamp
- save and close the history textfile
- Delete the ".bash-history" file so the next session will create a new history
- 在退出 bash 之前输入“history >> history.txt”[ENTER]
- 退出 bash 提示符
- 按住 Win+R 打开运行命令框
- 输入外壳:配置文件
- 打开“history.txt”以确认我的文本已添加
- 在新行上按 [F5] 输入时间戳
- 保存并关闭历史文本文件
- 删除“.bash-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.
如果你真的想要积分,我想你可以制作一个批处理文件来完成所有这些,但这对我来说已经足够了。希望它可以帮助某人。