Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Delete commit from array Ruby gitlab

I am trying to remove one of the objects from a gitlab array of several commits.

[
    {
        :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
    }
]

but when I go through the array I can’t delete the commit that contains the message "Merge remote".

I am trying this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

a = commits_with_status.delete_if { |x| commits_with_status.include? x["Merge remote"]}

the array is stored in the variable commits_with_status.

But I can’t delete the commit that has this message…

>Solution :

May be like this

a = commits_with_status.reject { |commit| commit[:commit].message == "Merge remote" }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading