Why did running `git pull` uninstall my fixes?

According to the git documentation, git pull will fetch the current branch and then run git merge to merge the changes. After a colleague made and pushed his changes to the server, I went to look for them.

Firstly, I made the changes that I had:

 git add src git add war 

Running git status confirmed that my changes were set to be perfect. Then I ran:

 git commit -m "Another commit to work on scrolling" 

Subsequently, I removed the changes:

 git pull 

This showed me some warnings:

 remote: Counting objects: 31, done. remote: Compressing objects: 100% (16/16), done. remote: Total 16 (delta 13), reused 3 (delta 0) Unpacking objects: 100% (16/16), done. From github.com:FullCreative/Loop + 3f00b3f...2e09a49 master -> master (forced update) Warning: fetch updated the current branch head. Warning: fast-forwarding your working tree from Warning: commit 3f00b3f6cb6ed6beddb16baa92f1beaa82b6944c. Already up-to-date. 

Finally, I pushed my changes - or rather tried to push them - to the server:

 git push 

Question:

Now, why did it delete all my changes? Even files that my colleague did not modify were deleted from my working directory.

Console exit:

For thoroughness, the console log from my terminal is presented below. This shows the commands that I ran and the output of these commands:

 jem@jem-VPCF136FM :~$ cd git jem@jem-VPCF136FM :~/git$ l Loop/ Loop-1-18.tar.gz jem@jem-VPCF136FM :~/git$ cd Loop jem@jem-VPCF136FM :~/git/Loop$ l Loop/ README readme.textile jem@jem-VPCF136FM :~/git/Loop$ l Loop/ README readme.textile jem@jem-VPCF136FM :~/git/Loop$ cd Loop jem@jem-VPCF136FM :~/git/Loop/Loop$ l src/ war/ jem@jem-VPCF136FM :~/git/Loop/Loop$ git add src jem@jem-VPCF136FM :~/git/Loop/Loop$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: src/com/fullcreative/loop/Globals.java # modified: src/com/fullcreative/loop/LoopController.java # modified: src/com/fullcreative/loop/LoopDao.java # modified: src/com/fullcreative/loop/LoopDaoJdo.java # modified: src/com/fullcreative/loop/LoopService.java # new file: src/com/fullcreative/loop/TestLoopController.java # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: war/WEB-INF/LoopDispatcher-servlet.xml # modified: war/WEB-INF/appengine-web.xml # modified: war/WEB-INF/applicationContext-security.xml # modified: war/WEB-INF/html/index.html # modified: war/WEB-INF/web.xml # modified: war/js/loop.js # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # war/WEB-INF/admin/local-storage.html jem@jem-VPCF136FM :~/git/Loop/Loop$ git add war jem@jem-VPCF136FM :~/git/Loop/Loop$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: src/com/fullcreative/loop/Globals.java # modified: src/com/fullcreative/loop/LoopController.java # modified: src/com/fullcreative/loop/LoopDao.java # modified: src/com/fullcreative/loop/LoopDaoJdo.java # modified: src/com/fullcreative/loop/LoopService.java # new file: src/com/fullcreative/loop/TestLoopController.java # modified: war/WEB-INF/LoopDispatcher-servlet.xml # new file: war/WEB-INF/admin/local-storage.html # modified: war/WEB-INF/appengine-web.xml # modified: war/WEB-INF/applicationContext-security.xml # modified: war/WEB-INF/html/index.html # modified: war/WEB-INF/web.xml # modified: war/js/loop.js # jem@jem-VPCF136FM :~/git/Loop/Loop$ git commit -m "Another commit to work on scolling" [master 3f00b3f] Another commit to work on scolling 13 files changed, 726 insertions(+), 218 deletions(-) create mode 100644 Loop/src/com/fullcreative/loop/TestLoopController.java create mode 100644 Loop/war/WEB-INF/admin/local-storage.html jem@jem-VPCF136FM :~/git/Loop/Loop$ git pull remote: Counting objects: 31, done. remote: Compressing objects: 100% (16/16), done. remote: Total 16 (delta 13), reused 3 (delta 0) Unpacking objects: 100% (16/16), done. From github.com:FullCreative/Loop + 3f00b3f...2e09a49 master -> master (forced update) Warning: fetch updated the current branch head. Warning: fast-forwarding your working tree from Warning: commit 3f00b3f6cb6ed6beddb16baa92f1beaa82b6944c. Already up-to-date. jem@jem-VPCF136FM :~/git/Loop/Loop$ git push Everything up-to-date jem@jem-VPCF136FM :~/git/Loop/Loop$ git status # On branch master nothing to commit (working directory clean) jem@jem-VPCF136FM :~/git/Loop/Loop$ git history git: 'history' is not a git command. See 'git --help'. jem@jem-VPCF136FM :~/git/Loop/Loop$ git --help usage: git [--version] [--exec-path[=<path>]] [--html-path] [-p|--paginate|--no-pager] [--no-replace-objects] [--bare] [--git-dir=<path>] [--work-tree=<path>] [-c name=value] [--help] <command> [<args>] The most commonly used git commands are: add Add file contents to the index bisect Find by binary search the change that introduced a bug branch List, create, or delete branches checkout Checkout a branch or paths to the working tree clone Clone a repository into a new directory commit Record changes to the repository diff Show changes between commits, commit and working tree, etc fetch Download objects and refs from another repository grep Print lines matching a pattern init Create an empty git repository or reinitialize an existing one log Show commit logs merge Join two or more development histories together mv Move or rename a file, a directory, or a symlink pull Fetch from and merge with another repository or a local branch push Update remote refs along with associated objects rebase Forward-port local commits to the updated upstream head reset Reset current HEAD to the specified state rm Remove files from the working tree and from the index show Show various types of objects status Show the working tree status tag Create, list, delete or verify a tag object signed with GPG See 'git help <command>' for more information on a specific command. jem@jem-VPCF136FM :~/git/Loop/Loop$ git log commit 2e09a498829e2b12e4bbdff8f8c39c2ce47dacb7 Author: Josh Iwata < josh@fullcreative.com > Date: Thu Mar 15 14:25:28 2012 -0700 Design revamp commit 2927f853041dab06a48861498adc945d6969865a Author: James Mortensen < james.mortensen@a-cti.com > Date: Wed Mar 14 09:25:46 2012 -0700 Removed Alert. commit 07deceb9cb3cda6b913b2bde96970682ecdbddb7 Author: James Mortensen < james.mortensen@a-cti.com > Date: Wed Mar 14 09:04:12 2012 -0700 Added url pattern to the servlet to get rid of the error. commit f2d48bb735e5c3f1d3cb88ad80483e5596aaa063 Author: James Mortensen < james.mortensen@a-cti.com > Date: Tue Mar 13 15:44:28 2012 -0700 iJames took over again! commit 88fb39c0b37b2dfc5a13e30f212cba525e33f531 Author: David Raffauf < david@fullcreative.com > Date: Tue Mar 13 15:42:26 2012 -0700 I test update commit 5b1af15d166fc766a1a892a13865d9c5be506a6f Author: Josh Iwata < josh@fullcreative.com > jem@jem-VPCF136FM :~/git/Loop/Loop$ git status # On branch master nothing to commit (working directory clean) jem@jem-VPCF136FM :~/git/Loop/Loop$ git pull Already up-to-date. jem@jem-VPCF136FM :~/git/Loop/Loop$ l src/ war/ jem@jem-VPCF136FM :~/git/Loop/Loop$ cd src jem@jem-VPCF136FM :~/git/Loop/Loop/src$ l cacerts.bin com/ log4j.properties META-INF/ jem@jem-VPCF136FM :~/git/Loop/Loop/src$ cd com jem@jem-VPCF136FM :~/git/Loop/Loop/src/com$ l fullcreative/ jem@jem-VPCF136FM :~/git/Loop/Loop/src/com$ cd fullcreative/loop/ jem@jem-VPCF136FM :~/git/Loop/Loop/src/com/fullcreative/loop$ l AbstractBaseController.java Comment.java LoopController.java PusheableResponse.java AccountController.java EmailService.java LoopDao.java samples/ Account.java EnvironmentService.java LoopDaoJdo.java security/ AccountService.java FormManagerController.java Loop.java Settings.java AuthenticatorController.java Globals.java LoopService.java TagSubscription.java AuthenticatorService.java GoogleCometChannelService.java LoopServlet.java UserDao.java Cacheable.java HttpRequestHandler.java Memcached.java UserDaoJdo.java Card.java InvitationDetailsDaoJdo.java OAuth2User.java User.java CardManagerController.java InvitationDetails.java OAuth2UserService.java CardTemplateService.java JSONPResponse.java PMF.java jem@jem-VPCF136FM :~/git/Loop/Loop/src/com/fullcreative/loop$ cd / jem@jem-VPCF136FM :/$ cd jem@jem-VPCF136FM :~$ cd workspace jem@jem-VPCF136FM :~/workspace$ l ActiveResponseWebService/ ConversionChromeApp.pem GAE Spring Security/ LoopSVN/ Adaptiv3ChatDemo/ ConversionChromeExtension/ GAE Spring Security Demo/ Loop.tar.gz Adaptiv3ChatDemo-2.zip ConversionSupportChromeApp/ gdata-samples-read-only/ ReverseProxyDemo/ Adaptiv3ChatDemo.zip ConversionSupportLive/ LexLegal/ rhino-for-webapps-demo/ AmazonC3Demo/ ConversionSupportLiveNew/ LexMatter/ SB4.0/ App-AnswerConnect/ ConversionSupportLiveNew2/ local_db.bin SB4.0_branch/ appengine-java-sdk-1.6.2.1/ ConversionSupportLive.zip Loop/ sokolove_lawfirm/ appengine-java-sdk-1.6.2.1.zip Conversion Support- Mobile/ Loop2/ test/ appengine-java-sdk-1.6.3.1/ ConversionSupportWebsite/ Loop-Oauth2-Demo/ Test/ appengine-java-sdk-1.6.3.1.zip ConverstionSupportMobileV1/ LoopRepo/ Thinclient-c3/ AppointmentSchedulingAppGAEJ/ ConverstionSupportMobileV2/ LoopRepo-1-12-2-.tar.gz Thinclient-c3.zip ChatClientWebservices/ datastore-indexes-auto.xml LoopRepo1-12.tar.gz ContactManagementSystemDataStore/ EchopassChatClient/ LoopRepo1-13.tar.gz ConversionChromeApp0.1.1109.6.crx FullTextSearchService/ LoopRepo.tar.gz jem@jem-VPCF136FM :~/workspace$ cd Loop jem@jem-VPCF136FM :~/workspace/Loop$ l Loop/ README readme.textile jem@jem-VPCF136FM :~/workspace/Loop$ cd Loop jem@jem-VPCF136FM :~/workspace/Loop/Loop$ l src/ war/ jem@jem-VPCF136FM :~/workspace/Loop/Loop$ cd src jem@jem-VPCF136FM :~/workspace/Loop/Loop/src$ l cacerts.bin com/ log4j.properties META-INF/ jem@jem-VPCF136FM :~/workspace/Loop/Loop/src$ cd com jem@jem-VPCF136FM :~/workspace/Loop/Loop/src/com$ l fullcreative/ jem@jem-VPCF136FM :~/workspace/Loop/Loop/src/com$ cd fullcreative/ jem@jem-VPCF136FM :~/workspace/Loop/Loop/src/com/fullcreative$ l loop/ jem@jem-VPCF136FM :~/workspace/Loop/Loop/src/com/fullcreative$ cd loop jem@jem-VPCF136FM :~/workspace/Loop/Loop/src/com/fullcreative/loop$ jem@jem-VPCF136FM :~/workspace/Loop/Loop/src/com/fullcreative/loop$ l AccountController.java Card.java LoopController.java Memcached.java UserDao.java Account.java Comment.java LoopDao.java OAuth2User.java UserDaoJdo.java AccountService.java EnvironmentService.java LoopDaoJdo.java OAuth2UserService.java User.java AuthenticatorController.java HttpRequestHandler.java Loop.java PMF.java AuthenticatorService.java InvitationDetailsDaoJdo.java LoopService.java samples/ Cacheable.java InvitationDetails.java LoopServlet.java security/ jem@jem-VPCF136FM :~/workspace/Loop/Loop/src/com/fullcreative/loop$ cd ../../../../ jem@jem-VPCF136FM :~/workspace/Loop/Loop$ cd ../../.. jem@jem-VPCF136FM :~$ cd git jem@jem-VPCF136FM :~/git$ l Loop/ Loop-1-18.tar.gz jem@jem-VPCF136FM :~/git$ cd Loop jem@jem-VPCF136FM :~/git/Loop$ l Loop/ README readme.textile jem@jem-VPCF136FM :~/git/Loop$ cd Loop jem@jem-VPCF136FM :~/git/Loop/Loop$ l src/ war/ jem@jem-VPCF136FM :~/git/Loop/Loop$ 

UPDATE:

I can access my commits by checking the hash:

 git checkout 3f00b3f6cb6ed6beddb16baa92f1beaa82b6944c 

So why are they not included in my push to server?

UPDATE # 2

git reflog :

 3f00b3f HEAD@ {0}: checkout: moving from master to 3f00b3f6cb6ed6beddb16baa92f1beaa82b6944c 2e09a49 HEAD@ {1}: checkout: moving from 3f00b3f6cb6ed6beddb16baa92f1beaa82b6944c to master 3f00b3f HEAD@ {2}: checkout: moving from master to 3f00b3f6cb6ed6beddb16baa92f1beaa82b6944c 2e09a49 HEAD@ {3}: pull : forced-update 3f00b3f HEAD@ {4}: commit: Another commit to work on scolling 2927f85 HEAD@ {5}: commit: Removed Alert. 07deceb HEAD@ {6}: commit: Added url pattern to the servlet to get rid of the error. f2d48bb HEAD@ {7}: commit: iJames took over again! 88fb39c HEAD@ {8}: pull : fast-forward a22893e HEAD@ {9}: commit: Committing a very important change to intro.css. Not! ac19755 HEAD@ {10}: pull : fast-forward d2a401d HEAD@ {11}: commit: This is a test 85a6328 HEAD@ {12}: commit: Modified gitignore yet again. 251f557 HEAD@ {13}: commit: Committing the classpath. Hope it works. 4e7a428 HEAD@ {14}: checkout: moving from local_master to master 97aa2d7 HEAD@ {15}: checkout: moving from master to local_master 4e7a428 HEAD@ {16}: commit: Added Admin panel for making system changes. Modified the title and description so they go into edit 38dc2fa HEAD@ {17}: commit: Added notifications and real time comet. bc2f950 HEAD@ {18}: commit: Real time updates and chrome notifications. bc2f950 HEAD@ {19}: commit: Adding TagSubscription class. 5e696f4 HEAD@ {20}: commit: Bulk delete, fixed delete bug, tagging features and subscriptions. Added more server-side caching. Ad 7b41cc2 HEAD@ {21}: commit: adding dropdown plugin files d9e3716 HEAD@ {22}: commit: Added filter list to top, made dynamic, and deployed to 2-20. e256d21 HEAD@ {23}: commit: Cleaned up the HTML code. d9e3716 HEAD@ {24}: commit: Third time is a charm. 3e0863f HEAD@ {25}: commit: Here is the 2nd commit for tag-it. 13e70c8 HEAD@ {26}: commit: Added the tag-it tags to the application and connected to the database. 0893615 HEAD@ {27}: commit: Deployed 2-7 and made default version. 0073e04 HEAD@ {28}: commit: Deployed to 2-7 and made the default version. Finalized mobile form, although the error class shadow 0073e04 HEAD@ {29}: commit: test 4351a93 HEAD@ {30}: commit: Added notifications for comments and cleaned up mobile form. 5674cfb HEAD@ {31}: commit: Added Developer API call to switch users for @loopround.com users. a22808f HEAD@ {32}: commit: updating 8fa1a39 HEAD@ {33}: commit: updating the repository 8fa1a39 HEAD@ {34}: commit: Deployed to http://0-9-2012-1-27.loopaback.appspot.com/ 4786be1 HEAD@ {35}: commit: Updating the inbox counts on each loop on page load. Also changed the style of the inbox count on the 33bf8d5 HEAD@ {36}: commit: Adding elastic JS library. 095d8e6 HEAD@ {37}: commit: Hooked up inbox counts and colors on the loops. d3275ef HEAD@ {38}: commit: committing. a66024c HEAD@ {39}: commit: Put in place email notifications for sharing. Put in place more logging statements to catch errors. F a66024c HEAD@ {40}: commit: Fixed sharing settings and cleaned up some of the code. Fixed the invitation system and also added so e87ca75 HEAD@ {41}: commit: Fixed sharing settings and cleaned up some of the code. Fixed the invitation system and also added so e87ca75 HEAD@ {42}: commit: Got rid of login form and also integrated Loop feedback form. b2d7da9 HEAD@ {43}: commit: Eliminated the login page and also integrated the Feedback Loop Form. b2d7da9 HEAD@ {44}: commit: Added the Loop Form. e7ea0eb HEAD@ {45}: commit: Added the Loop Form to the Loop Application and connected it to the services. e7ea0eb HEAD@ {46}: commit: Trying to get all the files for the settings page in the repo. 97aa2d7 HEAD@ {47}: commit: test 36d4841 HEAD@ {48}: commit: Got the settings page in place so users can be added and removed. cf83cbd HEAD@ {49}: commit: Committing this file because I want it to accept changes, not have the repository just simply force m e7ccb2d HEAD@ {50}: commit: Merged Josh changes, I hope! 90ee5a5 HEAD@ {51}: commit: Merged Josh changes. Why I have to do this manually, I don't know? 3fc14b4 HEAD@ {52}: commit: Service giving ability to send email to a user. 2ce4a6c HEAD@ {53}: commit: Worked on the UI for adding a user to a Loop. Also fixed the display so it shows all active users ass 21caa9b HEAD@ {54}: commit: Updated the application-manifest.xml file with the new LoopRound name and latest version info. 4330694 HEAD@ {55}: commit: Deployed to http://0-9-2012-1-12-1715.loopaback.appspot.com/# and made the default version. Added in adde3cd HEAD@ {56}: commit: Can now add new loops from the Loop screen. To rename the loop or access it settings page; currentl 6902710 HEAD@ {57}: commit: Settings page is functional to edit the loop name. 6980c79 HEAD@ {58}: merge branch 'master' of git@github.com :FullCreative/Loop.git: Fast-forward e364173 HEAD@ {59}: commit: Added Josh CSS to style.css. 2nd attempt. 0e464f1 HEAD@ {60}: 

.git / configuration file

 [core] repositoryformatversion = 0 filemode = true logallrefupdates = true autocrlf = false [remote "origin"] url = git@github.com :FullCreative/Loop.git fetch = +refs/heads/*:refs/heads/* push = refs/heads/*:refs/heads/* [branch "master"] remote = origin merge = refs/heads/master 
+6
source share
4 answers

The following lines look suspicious:

 From github.com:FullCreative/Loop + 3f00b3f...2e09a49 master -> master (forced update) Warning: fetch updated the current branch head. Warning: fast-forwarding your working tree from Warning: commit 3f00b3f6cb6ed6beddb16baa92f1beaa82b6944c. 

In particular, if you are configured correctly, the line should indicate master -> origin/master , or whatever the name of your remote is. Instead, it reads master -> master . This means that the master branch on the remote control is written directly to the master branch in your local repo; which means that you are losing the link to your commit (although, as you noticed, it is still in your repo, it just doesn’t refer to it). This is why git is printed "Warning: fetch updates the current branch branch."

Check out .git/config . It should contain something like:

 [remote "origin"] url = <some url> fetch = +refs/heads/*:refs/remotes/origin/* 

However, based on the error received, it probably contains something like:

 [remote "origin"] url = <some url> fetch = +refs/heads/*:refs/heads/* 

This tells git that when fetching, it should write the value of the remote branch directly to your local branch. Usually, in the correct configuration above, when you retrieve the remote ref, it is written to refs/remotes/<remote>/<name> . This allows you to track both up-fix and local-fix so you can combine them. In the wrong configuration, you simply overwrite your local ref, losing the original information about what you had there.

I'm not sure how you are set up this way; maybe you did something like git clone --mirror or git remote add --mirror=fetch . Regardless, you can manually edit your .git/config file and fix the fetch line as described above.

+8
source

I think the key to the problem lies in the ominous message about your pull command: see where it says "force update"? This Git is a slightly obscure way to tell you that the branch (master) was either recreated or recreated, a big no-no in the general repository.

You should ask other collaborators if they recreated or re-created the wizard. If you want to see what happened, try gitk - all.

You probably don’t have a great way to solve your problem, but to do something difficult - cherry grip, which one performs on master ( git cherry-pick 3f00b3f ) and then clicks again.

+6
source

To fix this, enter:

 git checkout master; git merge 3f00b3f6cb6ed6beddb16baa92f1beaa82b6944c 

Then go slug jerk who ran git push --force

+2
source

The same thing happened to me, and this post led me to a solution using the git and git bash extensions.

Since I used git extensions, I did not have a console window to see the history of what I did. Also, I have not received any warnings, and I rarely use git bash, so I am not familiar with it.

I found the commit id by looking at [project path] \. git \ logs \ HEAD. This was the last bit of information:

 commit: ################ d511e44dca8c3f7f6f8d3985f3ca54874fb67a63 673fd2fbfc5ad78434389c64565904f81aa9a5ad unknown <###.(none)> 1444281107 -0500 pull --progress I:/####/#####+refs/heads/master:refs/heads/master: forced-update 

I did not force the update manually. I tried to pull / push from / to an external drive, and the letter has changed since the last time I did this, so I tried to remember how I installed it the first time, and I did something wrong. Perhaps this is due to the use of the URL field instead of the Remotes field.

To fix this, I used this in git bash:

 git checkout 673fd2fbfc5ad78434389c64565904f81aa9a5ad 

which uploaded the code to VS2010 without a branch. Then I used git extensions to create a new branch for the code, switch back to the master, and merge the new branch back into master. It will be the same as

 git checkout master; git merge 673fd2fbfc5ad78434389c64565904f81aa9a5ad 

So this is almost the same solution as the others, except that I needed to find the commit identifier in a different way.

0
source

Source: https://habr.com/ru/post/910852/


All Articles