Removing Git commits from HCP

When developing on HCP either from the WebIDE or local environments the ability to delete branch commits can become quite a hassle. The following guide provides a quick work around for deleting commits off your HCP git repositories.

After following the robust HCP git and feature branch strategy by DJ Adams, I discovered that the HCP cockpit restricts users from deleting both master and development branches/ versions. Attempting to remove branch commits with tools such as Source Tree didn’t seem work for me however I was able to remove commits from both branches using git bash/command.

Deleting HCP master branch commits

In order to remove a master branch commit from HCP you first need to reset the HEAD to point to the version you would like to revert to.

Step 1 – Switch to your master branch:

git checkout origin master

Step 2 – Load up the list of commits:

git log

A list of commits will be displayed as follows:

commit db854254…………………………………01ab49dfa3s4

Author: s00012345678 <user@gmail.com>

Date:   Thu Jul 23 15:13:02 2015 +0000

Commit of version: 0.1

commit h12b6dg9…………………………………3edfg88f35a1

Author: HCProxy <hcproxy@git.hana.ondemand.com>

Date:   Thu Jul 23 04:46:02 2015 +0000

Initial empty repository

Step 3 – Delete the latest commit ‘version: 0.1’:

git reset –hard HEAD^

This will move the head down one place from the top of the list to the ‘Initial empty repository’ commit.

If you need to move the HEAD down two positions (deleting the last two commits) from the top of the list you can use:

git reset –hard HEAD2-2

Step 4 – Force update the master branch:

git push –f

A confirmation message will be displayed notifying you that the force update has been successfully pushed to the master branch.

remote: Processing changes: refs: 1, done   

To https://git.hana.ondemand.com/myapp

+ h12b6… dfg88f35a1 master -> master (forced update)

Refreshing the HCP Commits in the History section will show that the master branch commit(s) have been removed and updated.

Before:

Screen Shot 2015-08-14 at 23.57.49.png

After:

Screen Shot 2015-08-14 at 23.58.28.png

Deleting HCP development branch versions

In order to remove a tagged’ development branch/version from your repo you can use the following git command:

git push origin :refs/tags/v1.5

Where ‘v1.5’ represents the name of your tag, the following deletion confirmation will be displayed:

remote: Processing changes: refs: 1, done   

To https://git.hana.ondemand.com/myapp

– [deleted]         v1.5

Refresh the HCP cockpit once again will show that version ‘v1.5’ has been successfully removed from the versions list.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Jan Penninkhof

    Very useful, thanks for the write-up.

    Always liked the git push – f statement 🙂

    (0) 

Leave a Reply