Reputation: 4465
in my visual studio project I have a repo from visual studio team services and I am using git for my version controlling, I made some changes to some files and then also I added a huge video file to my assets, I accidently forgot to add that file extension to my gitignore file and I made a commit locally and then I pushed it.
I had total 13 changes and on the 5th change being pushed ( the video file ) it is taking too long, and I don't want to push that video file in my vsts. I tried to do revert to that commit but it failed, I only want to keep those changes in my files and want to push them but I don't wanna push the video file, now I am stuck, what should I do to achieve this?
Upvotes: 2
Views: 1651
Reputation: 4465
I solved this issue with following steps:
Upvotes: 1
Reputation: 1309
Run the following command from the project root directory.
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch path/to/your/video' --prune-empty --tag-name-filter cat -- --all
Upvotes: 0
Reputation: 490098
Git doesn't push changes, nor does it push files. Git pushes—and fetches, for that matter—commits. The unit of each transaction is some whole number of commits (well, zero is also allowed; perhaps it would be better to say natural number of commits). Now, each commit is a snapshot of files, so files come along for the ride with the commits. But what git push
pushes is the commits, not the files. (After pushing the commits, git push
also sends a set of "change or create this branch name" requests as well, but we need not worry about that here.)
What you must do, then, is replace your bad series of commits with a series of new, improved commits instead.
For a linear sequence of commits, the easiest way to remove the bad file from the point where you added it onward is to use interactive rebase. There are many other ways to do this, though, and there is a post that covers all of this in great detail in many answers: How to remove/delete a large file from commit history in Git repository? See Greg Bacon's answer in particular to use interactive rebase to fix the problem.
Upvotes: 3
Reputation: 2654
Since you have only commited and not pushed yet, try this
git reset --soft HEAD~1
git rm --cached VideoFile.mp4
git commit ...
git push ....
Upvotes: 2