Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在CLI上的git树上自动滚动到git哈希提交的位置 背景_Git - Fatal编程技术网

如何在CLI上的git树上自动滚动到git哈希提交的位置 背景

如何在CLI上的git树上自动滚动到git哈希提交的位置 背景,git,Git,我通常坚持使用git cli进行所有git操作。我唯一一次使用GitGUI工具是当我想查看git提交相对于树的位置时 现在我有一个命令行显示git树: git log --graph --decorate --pretty=oneline --abbrev-commit --all 这给我展示了一个漂亮的树插图: * 6068f4b (origin/develop) exclude arm64 architecture * d49b4be Fix crash for global mark j

我通常坚持使用git cli进行所有git操作。我唯一一次使用GitGUI工具是当我想查看git提交相对于树的位置时

现在我有一个命令行显示git树:

git log --graph --decorate --pretty=oneline --abbrev-commit --all
这给我展示了一个漂亮的树插图:

* 6068f4b (origin/develop) exclude arm64 architecture
* d49b4be Fix crash for global mark jump in Xcode12
*   6e32166 Merge branch 'master' into develop
|\
| * 6356710 (HEAD -> master, origin/master, origin/HEAD) README.md
* | b126142 update project
* | 3b050e5 Failing Unit Test is commented out with FIXME comment addition
* | caad84d improve test
* |   0bc3054 Merge branch 'master' into develop
|\ \
| |/
| * a4a4fdb Fix Yank
* |   39d38ce Merge pull request #308 from chml/fix/yankAndPut
|\ \
问题 问题是,如果我想查看git哈希在该树中的位置,我必须执行以下操作:

  • 运行git签出
  • 运行git日志--graph--decoration--pretty=oneline--abbrev commit--all
  • 手动在git树上滚动一段时间,直到我看到
    HEAD
    指向的位置为止(对于年期的git回购,这可能需要一段时间)
  • 切换回我原来的提交
    git checkout
问题: 我希望使用一个命令将所有这些步骤合并为一个步骤(因此我应该避免更改git头commit)。对于GitGUI来说,这是一个非常直接的操作(gitkraken和sourcetree都提供了开箱即用的操作)。例如,在sourcetree中,这是一个跳转到提交的操作:


建议?

让我们在bash中完成,打开
.bashrc
~/.bash\u profile

vim~/.bashrc

让我们为您最初使用的git命令创建一个别名,这样您就不必一直键入它

alias gitTree="git log --graph --decorate --pretty=oneline --abbrev-commit --all"
现在,让我们编写一个函数来显示头部

function gshow(){
    git checkout "$1" --quiet
    git log --graph --decorate --pretty=oneline --abbrev-commit --all | grep "(HEAD)"
    git checkout - --quiet
}
关闭该文件,并从终端
source~/.bashrc
source~/.bash\u配置文件

现在你从终点站呼叫它

gshow <target-hash>
用法示例:

没有上下文参数 使用上下文arg
git log | grep-c7 HEAD
@AlexLarionov在您的命令中
放在哪里?这是搜索模式,而
-c7
标志表示要显示上下文的行数如果您使用寻呼机,有
\less-p
。不过,我不知道如何使用终端模拟器。它可能是特定于实现的。git使用的寻呼机通常是
较少的
,它有一个集成的搜索功能:键入
/
,然后键入
,然后键入
[输入]
。这就是你想要的答案吗?我更新了你的答案,希望你不要介意(我给了你正确的答案)@abbood,当然,我不:)这让答案变得更好!非常感谢你!这是一个快乐的人:)有了你的回答,我不会再在我的生活中使用GitGUI了!
function gshow(){
    ARG2=${2:-10}
    git checkout "$1" --quiet
    git log --graph --decorate --pretty=oneline --abbrev-commit --all | grep -C $ARG2 "(HEAD)"
    git checkout - --quiet
}
$ gshow 0bc3df2
|\ \ \
| * | | dff86b7 Add an FAQ on why users need to resign Xcode to use Xvim2
| | |/
| |/|
* | |   d267b5f Merge pull request #173 from 99arobe/task/update-README-to-remove-dead-link
|\ \ \
| |/ /
|/| |
| * | 64ecb94 Remove contributing guidelines from the README
|/ /
* | 0bc3df2 (HEAD) add comment
* | 2bddec1 add header update command comment
* | e244543 update Xcode10 beta3 header
* |   763b317 Merge branch 'master' into develop
|\ \
| |/
| *   2e50b5a Merge pull request #154 from rick-kilgore/master
| |\
| | * fc3eb9c fudge for the lines that might be only partially shown
| | * 62efd89 move logic into switch for XVIM_SCROLL_TYPE_LINE
| | * c4da83f allow scrolling to the first and last lines.  ensure cursor is in the right place
$ gshow 0bc3df2 20
|\ \ \
| |/ /
| * | ad28881 update branches and release readme
* | | 07d6820 deployment target 10.12 -> 10.13, swift -> 4.0
* | |   b06fbdf Merge pull request #177 from timothycosta/develop
|\ \ \
| * | | 2c48bcf Implemented 'source' command
| * | | 98cf07d Source xvimrc on toggle xvim
|/ / /
* | |   c725592 Merge pull request #175 from 99arobe/task/update-README-to-include-reasons-for-resigning-Xcode
|\ \ \
| * | | dff86b7 Add an FAQ on why users need to resign Xcode to use Xvim2
| | |/
| |/|
* | |   d267b5f Merge pull request #173 from 99arobe/task/update-README-to-remove-dead-link
|\ \ \
| |/ /
|/| |
| * | 64ecb94 Remove contributing guidelines from the README
|/ /
* | 0bc3df2 (HEAD) add comment
* | 2bddec1 add header update command comment
* | e244543 update Xcode10 beta3 header
* |   763b317 Merge branch 'master' into develop
|\ \
| |/
| *   2e50b5a Merge pull request #154 from rick-kilgore/master
| |\
| | * fc3eb9c fudge for the lines that might be only partially shown
| | * 62efd89 move logic into switch for XVIM_SCROLL_TYPE_LINE
| | * c4da83f allow scrolling to the first and last lines.  ensure cursor is in the right place
| | * 17ab836 don't move cursor on ctrl-e, ctrl-y
| |/
* | 7f4943d update the mangled signature of addSelectedRange
* | ac3faea fix #161 Xcode 10: Crash while edit in 'build phases'
* | 7dc4ea9 fix #158 not work C-f,C-b,C-u,C-d in Xcode10
* | 6397eff improve swift source
* | 9415303 add logger for swift
* | dae173f change swift function pointer address for Xcode10
* | d95e598 change from Xcode9.3 header to Xcode10
* | da8b31d class-dump Xcode10