pretzlstyle
pretzlstyle

Reputation: 2962

How to sync only my latest commit with git?

My local repository is ahead of remote by 2 commits - commit A and commit B.

Commit A was made first, and contains a very large file by accident, which is too large to stage and is causing a failure on push.

So, I deleted the file, untracked it, and then made commit B. However, I cannot push commit B, because then both commit A and B are attempting to push, which leads to commit A causing the same failure before B can be pushed.

Is there any way to tell git to ignore the first of these two commits? Or to "delete" commit A?

Upvotes: 2

Views: 1367

Answers (3)

Carlos Laspina
Carlos Laspina

Reputation: 2231

Maybe you can reset all commits and start again, with a clean stack.

  • git reset --soft HEAD~2 and then git commit -am "cleaned commit".

Upvotes: 3

gcbenison
gcbenison

Reputation: 11963

Another choice is git rebase -i HEAD^^. If you squash commits A and B together, there will be no record in the resulting commit of the offending file. This approach will also give you a chance to recycle some of your original commit message for commit A into the new resulting commit, if you desire.

Upvotes: 3

Will
Will

Reputation: 7027

You could use cherry-pick.

Assuming your remote branch is master and your branch with both commits is master-plus-a-and-b:

git checkout master
git checkout -b master-plus-b
git cherry-pick master-plus-a-and-b

Now master-plus-b has only master's commits and commit b, not commit a. You may have to cleanup any conflicts during the cherry-pick process.

Upvotes: 0

Related Questions