简体   繁体   中英

Git remove only push last local commit

I have made a bunch of changes on my local git version of a Rails project that I don't want to lose, however in doing so, I accidentally created a vendor/bundle folder in Git.

I realized as soon as I committed that I did this and did a git rm for the folder (and added the folder to gitignore), and committed again. However, now I can't push the original because the bundle is too large.

What I need

  • How can I keep the edits (and new files) I made.
  • While removing the bundle folder from git history
  • And not pushing that commit with them since the directory is too large

I've been searching SO for various ways of soft resetting here, but I'm stuck..

I think I found the answer:

This occurs fairly commonly. Someone accidentally commits a huge binary file with a thoughtless git add ., and you want to remove it everywhere. Perhaps you accidentally committed a file that contained a password, and you want to make your project open source. filter-branch is the tool you probably want to use to scrub your entire history. To remove a file named passwords.txt from your entire history, you can use the --tree-filter option to filter-branch:

Source :

git filter-branch --tree-filter 'rm -f /vendor/bundle' HEAD

您可以执行git reset --soft HEAD~x ,其中x是要重置的审阅数-在您的情况下为2,然后将目录添加到gitignore文件,并将其从暂存区域中删除。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM