Various pits of git+github (update)

Summarize the pits I guessed when using git

1. After using git push origin master, the terminal output is as follows

To https://github.com/gcusms/workplace
 ! [rejected]        master -> master (non-fast-forward)
error: 无法推送一些引用到 'https://github.com/gcusms/workplace'
提示:更新被拒绝,因为您当前分支的最新提交落后于其对应的远程分支。
提示:再次推送前,先与远程变更合并(如 'git pull ...')。详见
提示:'git push --help' 中的 'Note about fast-forwards' 小节。

Reason : I had the README.md file when I created the warehouse but it was not saved in my local path.
Solution : Open the terminal under the path that you need to upload to the github warehouse:
pull the master file to the current directory, and keep the files in the workspace consistent with the files in the warehouse.

git pull --rebase origin master

Then git push -u origin masteryou can

对象计数中: 16, 完成.
Delta compression using up to 8 threads.
压缩对象中: 100% (16/16), 完成.
写入对象中: 100% (16/16), 368.92 KiB | 6.59 MiB/s, 完成.
Total 16 (delta 0), reused 0 (delta 0)
To https://github.com/gcusms/workplace
   d6084f6..93a6ea1  master -> master

2Use git to delete files in the workspace by mistake

Previously used this command of git to delete the file:

git rm -r handfind

Open the terminal and enter two sentences at the location of the deleted file

git reset HEAD 文件名称
git checkout 文件名称

If there is no error, the file should be back

Guess you like

Origin blog.csdn.net/Msyusheng/article/details/114324289