Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What and where does one potentially lose stuff when git says "forced update"?

Tags:

git

I recently received a "forced update" warning from git on a repository which only I commit to. I haven't done any re-basing so I don't know why this happened. What I want to know is, where should I look to find changes that have potentially been lost?

To illustrate, let there be three copies of the repository, L, D and S (laptop, desktop, server).

To begin all three repositories are in-sync. Then work is done on D and pushed to S. Then L runs git pull and gets "forced update". Does this mean that there are changes made on L that have been overwritten, or are they somewhere else? How can I find them? Thanks.

like image 907
Sean Whitton Avatar asked Aug 21 '12 21:08

Sean Whitton


1 Answers

A "forced update" means the remote-tracking branch was recent. This happens if you fetch (or pull) after someone does a force push to the repository.

However, when executing the git pull, your local branch won't lose any history. Since the remote branch's history now diverges from your local, git pull will execute a merge. If you look at the most recent commit (just run git log) you should see a merge commit, with the first parent being the previous state of your local branch and the second parent being the new value of your remote branch.

For illustration, I just reproduced the forced update scenario, and a git pull prints the following:

> git pull remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 2 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (2/2), done. From /Volumes/UserData/Users/kballard/Dev/Scratch/foo/server  + 7193788...a978889 master     -> origin/master  (forced update) Merge made by the 'recursive' strategy.  0 files changed, 0 insertions(+), 0 deletions(-)  create mode 100644 d 

The fetch portion of the pull prints (forced update), but the new value of origin/master is subsequently merged into the local branch.

like image 51
Lily Ballard Avatar answered Sep 24 '22 06:09

Lily Ballard