HelloWorld
HelloWorld

Reputation: 93

How to modify or remove older commit in Git?

From past few days i had kept on adding and committing files in my local. My branch is now 16 commits ahead of 'origin/master'.

I wanted to push them to my git repo but one of the file being very large my push command fails. Is there any way to remove that commit from the stash or will i have to do a hard reset on the head.

Upvotes: 1

Views: 3965

Answers (4)

gerard
gerard

Reputation: 990

If you just want to remove the file then why not just do that by deleting the file and then committing the change?

Now, in your latest commit the file doesn't exist.

You should now be able to push your branch to the remote without any problem.

Upvotes: 0

CodeWizard
CodeWizard

Reputation: 141946

  1. You can use the squash
  2. BFG
  3. Move HEAD back to previous commit (link)

squash

# edit all the commits up to the given sha-1
git rebase -i <sha-1>

enter image description here


but one of the file being very large my push command fails...

How to remove big files from the repository

You can use git filter-branch or BFG. https://rtyley.github.io/bfg-repo-cleaner/

BFG Repo-Cleaner

an alternative to git-filter-branch.

The BFG is a simpler, faster alternative to git-filter-branch for cleansing bad data out of your Git repository history:

* Removing Crazy Big Files*
* Removing Passwords, Credentials & other Private data

Examples (from the official site)

In all these examples bfg is an alias for java -jar bfg.jar.

# Delete all files named 'id_rsa' or 'id_dsa' :
bfg --delete-files id_{dsa,rsa}  my-repo.git

enter image description here

Upvotes: 2

choroba
choroba

Reputation: 241748

If you just want to skip a commit, do git rebase -i master and select drop for the commit to be skipped. If you just want to remove a single file from it, select edit and amend the commit to remove the file.

Upvotes: 3

mohor chatt
mohor chatt

Reputation: 356

what you can do is you can use git rebase option and squash all the commits.

Upvotes: -1

Related Questions