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:
- From an account with Force Push permissions clone your repository containing the readme.md.
- use
git rebase -i HEAD~6
(6 being the number of commits to rewind)
- use
Squash
to merge the commits together
- 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.
- Make sure you have a copy of the file you want to keep.
- 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.
- Now copy your backed-up file back into place
- 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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…