简体   繁体   English

Git-自定义命令“ cd”

[英]Git - Custom command “cd”

Is it possible in the git custom command to change the console bash directory ? 可以在git custom命令中更改控制台bash目录吗?

My example code: 我的示例代码:

#!/bin/bash
# This is a test
cd /c/testfolder
ls

the code is working, but the cd only works on this block doesn't do any alteration on the bash. 代码可以正常工作,但是cd仅在此块上有效,对bash不会做任何更改。 在此处输入图片说明

So what I need it is the console / change to /c/testfolder 所以我需要的是控制台/更改为/c/testfolder

It is not possible for a command or shell script to cause the shell / console's current directory to change. 命令或Shell脚本无法更改Shell /控制台的当前目录。

(Unless you are executing the script in the shell itself using source / . . You can't do that with a git custom command because they are executed by a child process of git not by the console's shell.) (除非你使用执行脚本的shell本身source / . 。你不能这样做与git ,因为它们是由一个子进程执行的自定义命令git不是由控制台的外壳。)

See Bash script to change parent shell directory for a more detailed explanation of the base problem. 有关基本问题的更详细说明,请参见Bash脚本更改父Shell目录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM