Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Hard reset isn't erasing local commits
Hard reset isn't erasing local commits [message #1779100] Tue, 02 January 2018 19:53 Go to next message
David M. Karr is currently offline David M. KarrFriend
Messages: 559
Registered: July 2009
Senior Member
Using Eclipse 4.7.2 and egit 4.10.0.201712302008-r.

I'm on the master branch on a repo, which I've been working on for a long time, although I haven't committed or pushed anything for a week or two. Today I made some changes to a file, verified it was what I wanted, and then committed and pushed.

Surprisingly, it was rejected, saying something about "not fast forward merge".

Looking at the repo list, I see "^2" (uparrow, not caret), which is surprising, as I only attempted to commit and push one file).

So, I decided to start over, saving the changes I needed to make in an external file, and then selecting "Reset..." and then "Hard'. I've used this technique many times. Today, it seemed to do nothing. It did say it was resetting, and showing progress, but when it was done, my changed file was still in the state I had changed it to, and the repo list still shows "^2".

I'm confused.
Re: Hard reset isn't erasing local commits [message #1779109 is a reply to message #1779100] Tue, 02 January 2018 21:41 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1026
Registered: July 2009
Senior Member
"not fast forward merge" means that the commit(s) you are trying to push are not successors of the current tip of the upstream branch you are pushing to. This is typically caused by commits created by other developers who pushed their commits so that the respective hence the upstream branch moved. Your local commits are still based on a commit which was the tip of the upstream branch earlier. Git doesn't allow non-fast forward branch updates on push since this would kick out the commits the other developers pushed before you from the upstream repository's git history.

You can solve this in the following way:
- fetch from upstream to download any new commits other developers pushed
- have a look at the git history to see which commits were in your way (ensure that the toggle button "Show all branches and tags" is switched on in the history view).
- rebase your local branch on the updated remote tracking branch (most often this is origin/master). alternatively you can also merge the upstream branch into your local branch, but this adds a merge commit which makes history look more complex, hence I most often prefer rebase over merge for updating a local private branch with updates from upstream
- resolve conflicts if there are any
- test your rebased local branch (it happens rarely but any automatic merge or rebase can cause collateral damage since git doesn't understand your program but just does text manipulation)
- push your local branch, if you again get "not fast forward merge" someone else was faster than you and you have to rinse and repeat this procedure.

The up or down arrows in the repository's decorator show the distance in number of commits between your local branch and the respective remote tracking branch your local branch is tracking. Note that remote tracking branches can always be outdated if you didn't fetch from the upstream repository for a while. Other developers are pushing their changes to the upstream branch you started your work on and you need to fetch from time to time in order to download these updates to your local clone.
Re: Hard reset isn't erasing local commits [message #1779110 is a reply to message #1779109] Tue, 02 January 2018 21:43 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1026
Registered: July 2009
Senior Member
s/so that the respective hence the upstream branch moved/so that the respective upstream branch moved/
Re: Hard reset isn't erasing local commits [message #1779111 is a reply to message #1779110] Tue, 02 January 2018 21:49 Go to previous message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1026
Registered: July 2009
Senior Member
regarding the reset behavior you observed: is the file which wasn't reset maybe untracked (not yet versioned by git) ?
Untracked files have a ? decorator. See "preferences > Team > Git > Label Decorations" to see the decorators used in EGit
for the different possible git statuses of a file.
Previous Topic:How to ignore .ssh/config?
Next Topic:JGit LFS: Support to track a new file?
Goto Forum:
  


Current Time: Wed Jun 20 21:13:09 GMT 2018

Powered by FUDForum. Page generated in 0.02729 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top