Search code examples
pythongitgithubgit-mergegit-push

Git + Pycharm, push rejected error, files all gone


I am newbie programmer who uses Pycharm.
There's a function that made me able to connect my Pycharm and GitHub repository.
I didn't know how Git works, and I wanted to upload (push?) my codes and files to GitHub: It asked me if I want to merge, and I said yes.

Then the error message popped up:

Push rejected. Push was rejected, and update failed with an error

My files are all gone, and it was not pushed + I can't find the log for it.

git log: HEAD

I want to restore my codes and flies T_T
their names are 'crawl.py', 'cos_similarity.py', 'word_processor.py', 'nouns_compare.py', 'test.xlsx', and 'eta_assistant_results.txt'

git buttons on the top-right corner of Pycharm

I clicked the green arrow,

I got this message,

and I clicked the 'merge' button

In the git console, it says...

10:09:22.261: [chatbot-master] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -- crawler/crawl.py

10:33:46.504: [chatbot-master] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -- crawler/cos_similarity.py

10:49:21.180: [chatbot-master] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -- crawler/word_processor.py

11:09:36.143: [chatbot-master] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -- crawler/nouns_compare.py

12:37:25.049: [chatbot-master] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -- crawler/test.xlsx

13:42:23.357: [chatbot-master] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -- crawler/~$eta_assistant_results.xlsx

**error: open("crawler/~$eta_assistant_results.xlsx"): Permission denied
error: unable to index file
'crawler/~$eta_assistant_results.xlsx'**

open("crawler/~$eta_assistant_results.xlsx"): Permission denied

unable to index file 'crawler/~$eta_assistant_results.xlsx'

13:43:54.294: [chatbot-master] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -- crawler/eta_assistant_results.xlsx.rsmbk

**error: open("crawler/eta_assistant_results.xlsx.rsmbk"): Permission denied
error: unable to index file 'crawler/eta_assistant_results.xlsx.rsmbk'**

open("crawler/eta_assistant_results.xlsx.rsmbk"): Permission denied

unable to index file 'crawler/eta_assistant_results.xlsx.rsmbk'

15:40:07.371: [chatbot-master] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false push --progress --porcelain origin refs/heads/main:main

**error: failed to push some refs to 'https://github.com/SongJongbeen/chatbot.git'
hint: Updates were rejected because the remote contains work that you do**

To https://github.com/SongJongbeen/chatbot.git

!   refs/heads/main:refs/heads/main [rejected] (fetch first)

**hint: not have locally. This is usually caused by another repository pushing**

Done

**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.**

15:40:12.691: [chatbot-master] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false fetch origin --recurse-submodules=no --progress --prune

**remote: Enumerating objects: 6, done.     
remote: Counting objects:  25% (1/4)    
remote: Counting objects:  50% (2/4)        
remote: Counting objects:  75% (3/4)        
remote: Counting objects: 100% (4/4)        
remote: Counting objects: 100% (4/4), done.        
remote: Compressing objects:  33% (1/3)        
remote: Compressing objects:  66% (2/3)        
remote: Compressing objects: 100% (3/3)        
remote: Compressing objects: 100% (3/3), done.        
remote: Total 6 (delta 1), reused 1 (delta 1), pack-reused 2        
From https://github.com/SongJongbeen/chatbot
   71d62fe..733d1d4  main       -> origin/main**

15:40:14.844: [chatbot-master] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false restore --staged --worktree --source=HEAD -- crawler/crawl.py crawler/crawler.py crawler/nouns_compare.py crawler/test.xlsx crawler/cos_similarity.py crawler/word_processor.py

15:40:15.060: [chatbot-master] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false merge origin/main --no-stat -v

**error: The following untracked working tree files would be overwritten by merge:**
    **.idea/.name**
    **.idea/workspace.xml**

**Please move or remove them before you merge.**

**Aborting**

Solution

  • I didn't know how git works, and I wanted to upload (push?) my codes and files to github. It asked me if I want to merge, and I said yes.

    That happens when you create a new GitHub repository... initialized with files like README, and/or LICENSE.

    Try again, but this time with a GitHub repository completely new and empty: there should be no "merge" question when pushing then from PyCharm.

    Check in the PyCharm local history if you can restore your files that way: recreate them in a new folder, and re-try the all process from there.