从数组 Ruby gitlab 中删除提交
Delete commit from array Ruby gitlab
我正在尝试从多个提交的 gitlab 数组中删除其中一个对象。
[
{
:commit=>#<Git: :Object: :Commit: @base=#<Git: :Base: @logger=nil, @working_directory=#<Git: :WorkingDirectory: @path=" ">, @repository=#<Git: :Repository: @path=" /.git">, @index=#<Git: :Index: @path=" /.git/index">, @lib=#<Git: :Lib: @git_dir=" /.git", @git_index_file=" /.git/index", @git_work_dir=" ", @path=nil, @logger=nil, @git_system_env_variables={
"GIT_DIR"=>nil,
"GIT_WORK_TREE"=>nil,
"GIT_INDEX_FILE"=>nil,
"GIT_SSH"=>nil
}>>, @objectish="", @contents=nil, @trees=nil, @size=nil, @sha="", @tree=#<Git: :Object: :Tree: @base=#<Git: :Base: @logger=nil, @working_directory=#<Git: :WorkingDirectory: @path=" ">, @repository=#<Git: :Repository: @path=" /.git">, @index=#<Git: :Index: @path=" /.git/index">, @lib=#<Git: :Lib: @git_dir=" /.git", @git_index_file=" /.git/index", @git_work_dir=" ", @path=nil, @logger=nil, @git_system_env_variables={
"GIT_DIR"=>nil,
"GIT_WORK_TREE"=>nil,
"GIT_INDEX_FILE"=>nil,
"GIT_SSH"=>nil
}>>, @objectish="", @contents=nil, @trees=nil, @size=nil, @sha=nil, @mode=nil, @blobs=nil>, @parents=[#<Git: :Object: :Commit: @base=#<Git: :Base: @logger=nil, @working_directory=#<Git: :WorkingDirectory: @path=" ">, @repository=#<Git: :Repository: @path=" /.git">, @index=#<Git: :Index: @path=" /.git/index">, @lib=#<Git: :Lib: @git_dir=" /.git", @git_index_file=" /.git/index", @git_work_dir=" ", @path=nil, @logger=nil, @git_system_env_variables={
"GIT_DIR"=>nil,
"GIT_WORK_TREE"=>nil,
"GIT_INDEX_FILE"=>nil,
"GIT_SSH"=>nil
}>>, @objectish="", @contents=nil, @trees=nil, @size=nil, @sha=nil, @tree=nil, @parents=nil, @author=nil, @committer=nil, @message=nil>
], @author=#<Git: :Author: @name=" ", @email="", @date=2022-05-19 23: 02: 18 +0000>, @committer=#<Git: :Author: @name=" ", @email=" ", @date=2022-05-19 23: 02: 18 +0000>, @message="test: test it">,
:failed=>false
},
{
:commit=>#<Git: :Object: :Commit: @base=#<Git: :Base: @logger=nil, @working_directory=#<Git: :WorkingDirectory: @path=" ">, @repository=#<Git: :Repository: @path=" /.git">, @index=#<Git: :Index: @path=" /.git/index">, @lib=#<Git: :Lib: @git_dir=" /.git", @git_index_file=" /.git/index", @git_work_dir=" ", @path=nil, @logger=nil, @git_system_env_variables={
"GIT_DIR"=>nil,
"GIT_WORK_TREE"=>nil,
"GIT_INDEX_FILE"=>nil,
"GIT_SSH"=>nil
}>>, @objectish="", @contents=nil, @trees=nil, @size=nil, @sha="", @tree=#<Git: :Object: :Tree: @base=#<Git: :Base: @logger=nil, @working_directory=#<Git: :WorkingDirectory: @path=" ">, @repository=#<Git: :Repository: @path=" /.git">, @index=#<Git: :Index: @path=" /.git/index">, @lib=#<Git: :Lib: @git_dir=" /.git", @git_index_file=" /.git/index", @git_work_dir=" ", @path=nil, @logger=nil, @git_system_env_variables={
"GIT_DIR"=>nil,
"GIT_WORK_TREE"=>nil,
"GIT_INDEX_FILE"=>nil,
"GIT_SSH"=>nil
}>>, @objectish="", @contents=nil, @trees=nil, @size=nil, @sha=nil, @mode=nil, @blobs=nil>, @parents=[#<Git: :Object: :Commit: 55ecfdf44940 @base=#<Git: :Base: @logger=nil, @working_directory=#<Git: :WorkingDirectory: @path=" ">, @repository=#<Git: :Repository: @path=" /.git">, @index=#<Git: :Index: @path=" /.git/index">, @lib=#<Git: :Lib: @git_dir=" /.git", @git_index_file=" /.git/index", @git_work_dir=" ", @path=nil, @logger=nil, @git_system_env_variables={
"GIT_DIR"=>nil,
"GIT_WORK_TREE"=>nil,
"GIT_INDEX_FILE"=>nil,
"GIT_SSH"=>nil
}>>, @objectish="", @contents=nil, @trees=nil, @size=nil, @sha=nil, @tree=nil, @parents=nil, @author=nil, @committer=nil, @message=nil>
], @author=#<Git: :Author: @name=" ", @email="", @date=>, @committer=#<Git: :Author: @name="", @email=" ", @date=2022-05-19 23: 01: 37 +0000>, @message="Merge remote">,
:failed=>false
}
]
但是当我遍历数组时,我无法删除包含消息“Merge remote”的提交。
我正在尝试这个:
a = commits_with_status.delete_if { |x| commits_with_status.include? x["Merge remote"]}
数组存储在变量commits_with_status中。
但我无法删除包含此消息的提交...
可能是这样
a = commits_with_status.reject { |commit| commit[:commit].message == "Merge remote" }
我正在尝试从多个提交的 gitlab 数组中删除其中一个对象。
[
{
:commit=>#<Git: :Object: :Commit: @base=#<Git: :Base: @logger=nil, @working_directory=#<Git: :WorkingDirectory: @path=" ">, @repository=#<Git: :Repository: @path=" /.git">, @index=#<Git: :Index: @path=" /.git/index">, @lib=#<Git: :Lib: @git_dir=" /.git", @git_index_file=" /.git/index", @git_work_dir=" ", @path=nil, @logger=nil, @git_system_env_variables={
"GIT_DIR"=>nil,
"GIT_WORK_TREE"=>nil,
"GIT_INDEX_FILE"=>nil,
"GIT_SSH"=>nil
}>>, @objectish="", @contents=nil, @trees=nil, @size=nil, @sha="", @tree=#<Git: :Object: :Tree: @base=#<Git: :Base: @logger=nil, @working_directory=#<Git: :WorkingDirectory: @path=" ">, @repository=#<Git: :Repository: @path=" /.git">, @index=#<Git: :Index: @path=" /.git/index">, @lib=#<Git: :Lib: @git_dir=" /.git", @git_index_file=" /.git/index", @git_work_dir=" ", @path=nil, @logger=nil, @git_system_env_variables={
"GIT_DIR"=>nil,
"GIT_WORK_TREE"=>nil,
"GIT_INDEX_FILE"=>nil,
"GIT_SSH"=>nil
}>>, @objectish="", @contents=nil, @trees=nil, @size=nil, @sha=nil, @mode=nil, @blobs=nil>, @parents=[#<Git: :Object: :Commit: @base=#<Git: :Base: @logger=nil, @working_directory=#<Git: :WorkingDirectory: @path=" ">, @repository=#<Git: :Repository: @path=" /.git">, @index=#<Git: :Index: @path=" /.git/index">, @lib=#<Git: :Lib: @git_dir=" /.git", @git_index_file=" /.git/index", @git_work_dir=" ", @path=nil, @logger=nil, @git_system_env_variables={
"GIT_DIR"=>nil,
"GIT_WORK_TREE"=>nil,
"GIT_INDEX_FILE"=>nil,
"GIT_SSH"=>nil
}>>, @objectish="", @contents=nil, @trees=nil, @size=nil, @sha=nil, @tree=nil, @parents=nil, @author=nil, @committer=nil, @message=nil>
], @author=#<Git: :Author: @name=" ", @email="", @date=2022-05-19 23: 02: 18 +0000>, @committer=#<Git: :Author: @name=" ", @email=" ", @date=2022-05-19 23: 02: 18 +0000>, @message="test: test it">,
:failed=>false
},
{
:commit=>#<Git: :Object: :Commit: @base=#<Git: :Base: @logger=nil, @working_directory=#<Git: :WorkingDirectory: @path=" ">, @repository=#<Git: :Repository: @path=" /.git">, @index=#<Git: :Index: @path=" /.git/index">, @lib=#<Git: :Lib: @git_dir=" /.git", @git_index_file=" /.git/index", @git_work_dir=" ", @path=nil, @logger=nil, @git_system_env_variables={
"GIT_DIR"=>nil,
"GIT_WORK_TREE"=>nil,
"GIT_INDEX_FILE"=>nil,
"GIT_SSH"=>nil
}>>, @objectish="", @contents=nil, @trees=nil, @size=nil, @sha="", @tree=#<Git: :Object: :Tree: @base=#<Git: :Base: @logger=nil, @working_directory=#<Git: :WorkingDirectory: @path=" ">, @repository=#<Git: :Repository: @path=" /.git">, @index=#<Git: :Index: @path=" /.git/index">, @lib=#<Git: :Lib: @git_dir=" /.git", @git_index_file=" /.git/index", @git_work_dir=" ", @path=nil, @logger=nil, @git_system_env_variables={
"GIT_DIR"=>nil,
"GIT_WORK_TREE"=>nil,
"GIT_INDEX_FILE"=>nil,
"GIT_SSH"=>nil
}>>, @objectish="", @contents=nil, @trees=nil, @size=nil, @sha=nil, @mode=nil, @blobs=nil>, @parents=[#<Git: :Object: :Commit: 55ecfdf44940 @base=#<Git: :Base: @logger=nil, @working_directory=#<Git: :WorkingDirectory: @path=" ">, @repository=#<Git: :Repository: @path=" /.git">, @index=#<Git: :Index: @path=" /.git/index">, @lib=#<Git: :Lib: @git_dir=" /.git", @git_index_file=" /.git/index", @git_work_dir=" ", @path=nil, @logger=nil, @git_system_env_variables={
"GIT_DIR"=>nil,
"GIT_WORK_TREE"=>nil,
"GIT_INDEX_FILE"=>nil,
"GIT_SSH"=>nil
}>>, @objectish="", @contents=nil, @trees=nil, @size=nil, @sha=nil, @tree=nil, @parents=nil, @author=nil, @committer=nil, @message=nil>
], @author=#<Git: :Author: @name=" ", @email="", @date=>, @committer=#<Git: :Author: @name="", @email=" ", @date=2022-05-19 23: 01: 37 +0000>, @message="Merge remote">,
:failed=>false
}
]
但是当我遍历数组时,我无法删除包含消息“Merge remote”的提交。
我正在尝试这个:
a = commits_with_status.delete_if { |x| commits_with_status.include? x["Merge remote"]}
数组存储在变量commits_with_status中。
但我无法删除包含此消息的提交...
可能是这样
a = commits_with_status.reject { |commit| commit[:commit].message == "Merge remote" }