我正在初始化一个已经包含一些文件的git仓库
repo = Rugged::Repository.init_at(".")
我需要暂存该文件夹中的文件并提交它们。这是我尝试过的:
repo = Rugged::Repository.new(".")
index = repo.index
index.add_all()
options = {}
options[:tree] = index.write_tree(repo)
options[:author] = { :email => "testuser@github.com", :name => 'Test Author', :time => Time.now }
options[:committer] = { :email => "testuser@github.com", :name => 'Test Author', :time => Time.now }
options[:message] ||= "Making a commit via Rugged!"
options[:parents] = repo.empty? ? [] : [ repo.head.target ].compact
options[:update_ref] = 'HEAD'
Rugged::Commit.create(repo, options)
但是,如果我查看目录并运行git status
,我得到的是:
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: .editorconfig
deleted: .gitignore
deleted: Procfile
deleted: README.md
Untracked files:
(use "git add <file>..." to include in what will be committed)
.editorconfig
.gitignore
Procfile
README.md
1条答案
按热度按时间r6hnlfcb1#
这个解决方案将原始代码更新为当前的Rubocop标准,添加了一种通过编程创建一些文件的方法,并包含了@DeepParekh提供的建议。
输出为: