我正在编写一个Lua脚本,它创建一个目录,在其中创建一些文件并初始化git,将这些文件添加到其中并最终提交所有内容。但是,没有办法从Lua内部使用cd
(你可以,但它没有效果),所以我想知道git init
是否可能目录,git add
一些文件,最后是git commit -a -m "message"
,所有工作目录都是所需目录上方的目录。
编辑:-C
有效,谢谢大家。对于任何想知道的人,在Lua,cd
"重置"拨打os.execute
后结束。因此,os.execute("cd mydir"); os.execute("git init");
无法按预期工作。要使其发挥作用,请使用os.execute("cd mydir; git init;");
。
答案 0 :(得分:6)
通过关于-C的评论中的提示,我做了:
git init newStuff
Initialized empty Git repository in c:/fw/git/initTest/newStuff/.git/
在dir newStuff中创建git repo(我已经创建了)
然后我将两个文件添加到newStuff,并使用-C
从它的父级添加git -C newStuff/ status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
new1
new2
nothing added to commit but untracked files present (use "git add" to track)
我看到了新文件。现在添加并提交它们:
git -C newStuff/ add .
git -C newStuff/ status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: new1
new file: new2
git -C newStuff/ commit -m"initial"
[master (root-commit) bfe387b] initial
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 new1
create mode 100644 new2
答案 1 :(得分:3)
关于shell的例子:
#!/bin/sh
dirPath=some/dir/path
mkdir -p $dirPath
touch $dirPath/newFile
git init $dirPath
git -C $dirPath add .
git -C $dirPath commit -a -m "Initial commit"
git -C $dirPath log