git init,添加,从另一个目录提交

use*_*072 6 git cd working-directory

我正在编写一个Lua脚本,它创建一个目录,在其中创建一些文件并初始化git,将这些文件添加到它并最终提交所有内容.然而,没有办法cd从Lua内部使用(你可以,但它不会有效),所以我想知道是否可以git init使用目录,git add一些文件,最后git commit -a -m "message",工作目录是所需目录上方的目录.

编辑:-C工作,谢谢大家.对于任何想知道的人,在Lua中,cdos.execute结束通话后"重置" .所以,os.execute("cd mydir"); os.execute("git init");不会按预期工作.要使它工作,请使用os.execute("cd mydir; git init;");.

Ran*_*ght 6

通过关于-CI的评论中的提示做了:

git init newStuff
Initialized empty Git repository in c:/fw/git/initTest/newStuff/.git/
Run Code Online (Sandbox Code Playgroud)

在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)
Run Code Online (Sandbox Code Playgroud)

我看到了新文件.现在添加并提交它们:

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
Run Code Online (Sandbox Code Playgroud)


小智 6

外壳示例:

#!/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
Run Code Online (Sandbox Code Playgroud)