overwriting some files in git remote

ghostrider

I am using git and apparently I screwed something up.

So, I have my local PC (called A), then my local PC (called B), and my remote.

After a series of of events (forgot to pull stuff, and then worked locally and so on) the situation goes like this :

  • remote has a copy
  • both of my local files have different changes
  • in the last week I have been making changes from local PC B. So local PC A has rev 2 let's say, and local PC B has rev 11 (latest of server) but both of them have different local changes

On my attempt to see what to do, I made things even worse.

  • I pushed data from local PC A (maybe forcing it - I am not sure)

But these removed all my other changes. I don't know how I managed that.

Not only that, but all my commits made from PC B (rev 3 to 11) lets say are gone from history - I cannot see them anywhere.

So, I have my remote and local PC to have the same data - and local PC B to have changes in it.

I know the files I have changes these two weeks - so I am trying the following (lets say it is one file - file.php)

git add file.php
git commit -m "test"

no changes added to commit

whey trying to push something I see something like this :

error: failed to push some refs to 'https://github.com/<url>'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

So what I need to do?

What I want to do is - just push this file to my remote and then I will just do git pull to sync everything.

I am doing stuff from command line, not using any GUI since I am working on VirtualBox.

Also, if I do :

git status

I see one file as modified.

Then If I commit this one - everything goes fine but I cannot push that into server because of the previous error. Mind that this behaviour only happens for files that belong to a folder that does not exist at all in the remote branch.

Klas Mellbourn

Your main problem seems to be that you have "lost" commits on PC B.

You have probably forced pushed them from A and then pulled those changes in B, and by doing that lost track of your changes on B.

You should be able to find the lost commits by running

git reflog

On PC B. This will show the changes of the HEAD pointer on PC B. Examine the output. It should contain commit messages and suchlike. When you find the rev 11 commit on PC B, do a

git reset --hard <hash of rev 11>

This will take you to the lost commit on PC B.

To be able to push these changes, you must resolve any conflicts with your remote. Do this by making a standard

git pull

This should trigger a merge between your local changes and the changes on your remote. When you have resolved those you should be able push again.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

overwriting some files in git remote

From Dev

git not overwriting remote repo with local files?

From Dev

`git checkout branch -- .`, without overwriting existing files

From Dev

Make git ignore and keep local changes to some files (vs different version in remote)

From Dev

Git remote repo, not showing the files

From Dev

Git Push Remote Modified files

From Dev

Remove remote .git Heroku files

From Dev

Git remote repo, not showing the files

From Dev

Git doesnt ignore some of the files

From Dev

Git-missing some files

From Dev

Git doesnt ignore some of the files

From Java

git error: failed to push some refs to remote

From Dev

Repository Behind Remote on Some Files Ahead on Others

From Java

How do I pull files from remote without overwriting local files?

From Dev

git remove all files except some files

From Dev

Git: Overwriting Multiple Commits on Remote Feature Branch after Local Rebase/Squash

From Dev

Git how can I restore local version previously overwriting by remote repository

From Dev

Transferring mp3 files from a remote server via cronjob to the RPi without overwriting

From Dev

Remove files from git without interfering with remote

From Dev

Will git push --force delete remote files?

From Java

Force "git push" to overwrite remote files

From Dev

How to assign local files with git remote?

From Dev

Remove .pyc files from Git remote repository

From Dev

"git push" deletes untracked remote files

From Dev

Remove files from remote branch in git

From Dev

How to git rm files that are on remote origin but not in local?

From Dev

Remove files from git without interfering with remote

From Dev

Git not pushing new files to remote repository

From Dev

Git remove tracked files, but keep local AND remote

Related Related

  1. 1

    overwriting some files in git remote

  2. 2

    git not overwriting remote repo with local files?

  3. 3

    `git checkout branch -- .`, without overwriting existing files

  4. 4

    Make git ignore and keep local changes to some files (vs different version in remote)

  5. 5

    Git remote repo, not showing the files

  6. 6

    Git Push Remote Modified files

  7. 7

    Remove remote .git Heroku files

  8. 8

    Git remote repo, not showing the files

  9. 9

    Git doesnt ignore some of the files

  10. 10

    Git-missing some files

  11. 11

    Git doesnt ignore some of the files

  12. 12

    git error: failed to push some refs to remote

  13. 13

    Repository Behind Remote on Some Files Ahead on Others

  14. 14

    How do I pull files from remote without overwriting local files?

  15. 15

    git remove all files except some files

  16. 16

    Git: Overwriting Multiple Commits on Remote Feature Branch after Local Rebase/Squash

  17. 17

    Git how can I restore local version previously overwriting by remote repository

  18. 18

    Transferring mp3 files from a remote server via cronjob to the RPi without overwriting

  19. 19

    Remove files from git without interfering with remote

  20. 20

    Will git push --force delete remote files?

  21. 21

    Force "git push" to overwrite remote files

  22. 22

    How to assign local files with git remote?

  23. 23

    Remove .pyc files from Git remote repository

  24. 24

    "git push" deletes untracked remote files

  25. 25

    Remove files from remote branch in git

  26. 26

    How to git rm files that are on remote origin but not in local?

  27. 27

    Remove files from git without interfering with remote

  28. 28

    Git not pushing new files to remote repository

  29. 29

    Git remove tracked files, but keep local AND remote

HotTag

Archive