Git 摆设

打印 上一主题 下一主题

主题 886|帖子 886|积分 2658

参考:手把手教你入门Git — Git使用指南(Linux)
必要说明的是:
1、服务器linux系统中一般使用master分支,但github如今流行的是main分支;
解决方案是修改master分支位main分支
  1. git branch -m master main
  2. git push -u origin main
  3. git push origin --delete master
复制代码
2、出现 base) admin1@Ning:/media/admin1/hdd1/Code/GitCode/Man_Fish$ git push -u Man_Fish main
error: src refspec main does not match any
error: failed to push some refs to ‘https://github.com/Tongzi-Zhang/Man_Fish.git’
如果你还没有对本地仓库进行任何提交,那么 main 分支(或其他分支)不会存在。Git 会报错由于没有可推送的内容。
解决方法:
创建一个提交,然后再进行推送:
bash
复制代码
git add .
git commit -m “Initial commit”
git push -u Man_Fish main
3、 (base) admin1@Ning:/media/admin1/hdd1/Code/GitCode/Man_Fish$ git push -u Man_Fish main
To github.com:Tongzi-Zhang/Man_Fish.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to ‘git@github.com:Tongzi-Zhang/Man_Fish.git’
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.
这个错误信息表明,远程仓库的 main 分支包含本地仓库没有的内容,因此你的推送被拒绝了。这通常是由于:
远程仓库的 main 分支有新的提交,而你本地的 main 分支还没有同步这些更改。
解决方案

  • 拉取远程仓库的更改(git pull)
    你必要先将远程仓库的更改拉取到本地,然后合并这些更改,解决可能的冲突,再进行推送。
拉取远程仓库的更新:
  1. git pull origin main
复制代码
这将会拉取 origin(远程仓库)上的 main 分支,并尝试将其合并到你本地的 main 分支。如果有冲突,Git 会提示你解决冲突。
解决冲突(如果有的话):
如果你拉取时遇到合并冲突,Git 会告诉你哪些文件有冲突。你必要手动编辑这些文件,解决冲突后,执行以下下令标记冲突已解决:
  1. git add <conflicted_file>
复制代码
提交合并:
完成冲突解决后,提交合并:
  1. git commit -m "Merge remote-tracking branch 'origin/main' into main"
复制代码
推送更改到远程仓库:
一旦合并完成,推送到远程仓库:
bash
复制代码
git push -u Man_Fish main
2. 如果你不想合并远程更改,强制推送
如果你确定本地的更改比远程仓库的更改更重要,且你不希望保存远程的更改,你可以强制推送(留意:这会覆盖远程仓库的 main 分支历史,慎用)。
  1. git push -f Man_Fish main
复制代码
乐成!!

4、git更新后怎样上传
在Git中,如果你已经有了一个本地仓库并且已经更新了代码,你可以按照以下步骤进行代码的上传:
打开终端(Terminal)或下令提示符(Command Prompt)。
切换到你的本地仓库所在的目录。
使用git status下令查抄你的更改。
使用git add .下令将全部更改过的文件添加到暂存区。如果只想添加特定文件,可以使用git add 。
使用git commit -m "Your commit message"下令提交你的更改。
使用git push下令将你的更改上传到远程仓库。
以下是现实的下令示例:
  1. cd /path/to/your/local/repository  # 切换到本地仓库目录
  2. git status                          # 查看更改
  3. git add .                           # 添加所有更改过的文件到暂存区
  4. git commit -m "Update code"         # 提交更改,并附上提交信息
  5. git push Man_Fish main                          # 将提交推送到远程仓库
复制代码
5、回退到某个版本
参考:如安在 Git 中规复到历史版本

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

滴水恩情

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表