Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove intermediate commit in Visual Studio Online

I edited my README.md multiple times because I didn't see the preview button. Now my commit history is full of useless commits.

Can I remove some of them, or at least hide them ?

like image 479
geriwald Avatar asked Dec 31 '14 13:12

geriwald


People also ask

How do I remove a commit in Visual Studio?

To do the same in Visual Studio, right-click the commit you want to revert and then select Revert. After you confirm your action and the operation is complete, Visual Studio displays a success message and a new commit appears in the Outgoing section.

How do I remove a commit remotely?

To delete commits from remote, you can use the git reset command if your commits are consecutive from the top or an interactive rebase otherwise. After you delete the commits locally, push those changes to the remote using the git push command with the force option.

How do I delete an existing commit?

Removing the last commit To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits.


1 Answers

CAUTION

History rewriting can get your source control system in a pretty messed up state. Make sure you have a good backup of your sources in case anything goes wrong.

Git

Depending on your Team Project setup, the Readme.md is stored in a Git repository you can absolutely rewrite history and force push the squashed commits back to TFS, essentially making it forget the in-between data. This is done using git rebase and cannot be done through the Visual Studio Online site nor through the Visual Studio Tools for Git. You will need to do it from the commandline.

The whole process is explained very well in the Git-SCM wiki. You'll need to do the following steps:

  1. From an account with Force Push permissions clone your repository containing the readme.md.
  2. use git rebase -i HEAD~6 (6 being the number of commits to rewind)
  3. use Squash to merge the commits together
  4. use git push --force origin master to force the history rewrite on the remote

Note: this will change the hash of the commit and every commit that came after. After doing this, either warn all other contributors to resync or be sure that no others have worked on the repo after you made these commits.

TFVC

If your Team Project is configured using TFVC, then the process is slightly different.

  1. Make sure you have a copy of the file you want to keep.
  2. Destroy the file in source control using tf destroy $/Teamproject/readme.md, If need be you can use the /keephistory /stopat:C12345 option to destroy the data in specific change sets at the end of a file's history.
  3. Now copy your backed-up file back into place
  4. and check it in as you'd usually do or from the commandline tf add $/teamproject/reqadme.md followed by tf checkin. If you kept history around, TFVC will reconnect it. If you completely destroyed the history, TFVC will just add a new file.
like image 98
jessehouwing Avatar answered Oct 27 '22 21:10

jessehouwing