0

I am trying to connect a local repository (latest file versions) to a remote (old file versions). I followed these steps:

  1. git init and git remote add origin to connect to the remote.
  2. git add updated file.
  3. git commit -m "Message".
  4. git push origin master.

The commit was rejected with the message:

error: failed to push some refs to ... Updates were rejected because the remote contains work that you do not have locally. This is usually caused by another repository pushing to the same ref.

I realize that I need to stash/pull/pop stash as described here.

However, in the meantime, the file I tried to commit has disappeared. When I type git status, I don't see it anywhere. It's still in my local repository, but Git doesn't seem to be tracking it. Any idea how to fix this?

Christos Batzilis
  • 352
  • 1
  • 3
  • 12
atkat12
  • 3,840
  • 7
  • 22
  • 22
  • Thank you. I do see the commit using the command described willoller; vasan, i will try your advice. – atkat12 Jun 15 '18 at 23:58
  • 3
    What specifically do you think "`git init` to the remote" means, and how did you come to believe that? – jthill Jun 16 '18 at 01:53
  • @jthill thanks, I wasn't clear -- I should have said git init and connect to the remote. – atkat12 Jun 16 '18 at 15:26

3 Answers3

2

Git status shows your workspace status - since the commit was successful (only push failed), the file won't show up in status. If you pull and push, it will be sent to remote server properly however.

If you still want confirmation that your file is indeed git-tracked, use the git ls-files command:

git ls-files <filename>

Will echo back the file name if it is tracked, or won't print anything if it isn't.

Vasan
  • 4,810
  • 4
  • 20
  • 39
0
echo "# demoone" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/baluselenium/demoone.git
git push -u origin master

give the user name and password it will add to remote

Vasan
  • 4,810
  • 4
  • 20
  • 39
babu
  • 1
0

Check if the reflog to see if the commit is there. Git keeps track of updates to the tip of branches using a mechanism called reference logs, or "reflogs."

 git reflog show --all
Thiru
  • 2,541
  • 4
  • 25
  • 39