GitHub:修订间差异

来自牛奶河Wiki
跳到导航 跳到搜索
 
(未显示同一用户的1个中间版本)
第42行: 第42行:


=== Repository ===
=== Repository ===
  # clone 远程仓库
==== clone 远程仓库 ====
# 需要在当前 repositories 下 settings/Deploy keys 中有相应 RSA publickey
  # 客户端中 .ssh 中有相应的 id_rsa
  git clone [email protected]:ldscfe/pangolin.git
  git clone [email protected]:ldscfe/pangolin.git
   
  .-OR-.
  # token
  # 记录 token: Settings -> Developer Settings -> Personal access tokens -> tokens(classic)
Settings -> Developer Settings -> Personal access tokens -> tokens(classic)
# 记录 token
  git clone https://<Token Name>:<Token>@github.com/ldscfe/devudefj2.git
  git clone https://<Token Name>:<Token>@github.com/ldscfe/devudefj2.git
==== 刷新 ====
# 刷新
  git pull
  git pull
==== 增加文件 ====
# 增加文件
  git status          # 查看文件状态
  git status          # 查看文件状态
   
   
  git add $FN
  git add $FN
  git add .            # 所有
  git add .            # 所有
==== 提交 ====
  # 提交 (需要 git add)
  # 需要 git add
  git commit -m "comment content"
  git commit -m "comment content"
  git push
  git push
 
# 去除文件&目录: .gitignore,已 git add 的文件,在 .gitignore 中标识无效
==== 去除文件&目录 ====
# .gitignore
  log/
  log/
  target/
  target/
第70行: 第69行:
  .gitignore
  .gitignore
   
   
# 已 git add 的文件,在 .gitignore 中标识无效
  git rm -f ${FN}      # 已 git add 的文件,删除后.gitignore 中标识有效
  git rm -f ${FN}      # 已 git add 的文件,删除后.gitignore 中标识有效
 
==== 分支 ====
  # 分支之间切换、恢复文件、创建新分支等
  # 分支之间切换、恢复文件、创建新分支等
  git checkout <branch-name>          # 从当前分支切换到指定的分支 <branch-name>, 或主分支:master
  git checkout <branch-name>          # 从当前分支切换到指定的分支 <branch-name>, 或主分支:master
第78行: 第79行:
  git checkout -b <new-branch-name>    # 创建一个新分支 <new-branch-name> 并切换
  git checkout -b <new-branch-name>    # 创建一个新分支 <new-branch-name> 并切换
  ...
  ...
   
  # 推送本地和远程都存在的同名分支
  # Creating remote repositories
  git config --global push.default matching
==== Creating remote repositories ====
  git remote add ldscfe_cpp [email protected]:ldscfe/cpp.git
  git remote add ldscfe_cpp [email protected]:ldscfe/cpp.git
  git remote add ldscfe_pangolin [email protected]:ldscfe/pangolin.git
  git remote add ldscfe_pangolin [email protected]:ldscfe/pangolin.git
第85行: 第87行:
   
   
  #You can use the command git remote set-url to change a remote's URL.
  #You can use the command git remote set-url to change a remote's URL.
  git remote set-url <REMOTE_URL>  
  git remote set-url <REMOTE_URL>
 
# 需要指定下推同步的项目
git config --global push.default matching


=== Public Effect ===
=== Public Effect ===
第98行: 第97行:
* Your changes will be published as activity.
* Your changes will be published as activity.
* Actions history and logs will be visible to everyone.
* Actions history and logs will be visible to everyone.
=== Example ===
DT=`date '+%Y/%m/%d %H:%M:%S'`
git add .
git commit -m "User-defined class libraries, $DT"
git push
之前最好用 git status 确认一下。


=== Error ===
=== Error ===

2024年11月4日 (一) 11:20的最新版本

GitHub Person

价格计划(免费版)

  • Free
    • The basics for individuals and organizations
  • Unlimited public/private repositories
    • Host open source projects in public GitHub repositories, accessible via web or command line. Public repositories are accessible to anyone at GitHub.com.
  • 2,000 automation minutes/month
    • Free for public repositories
    • Use execution minutes with GitHub Actions to automate your software development workflows. Write tasks and combine them to build, test, and deploy any code project on GitHub.
  • 500MB of Packages storage
    • Free for public repositories
    • Host your own software packages or use them as dependencies in other projects. Both private and public hosting available.
  • New Issues & Projects (beta)
    • Community support
    • 免费(个人)版支持无限个数的私有(或公有)仓库, 每月2000分钟的自动构建时长, 单仓库最大 500M.
    • 查看详情: https://github.com/pricing
    • CI/CD,全称:持续集成 (Continuous Integration) ,持续部署 (Continuous Deployment) ,是开发流程的自动化利器

Git

  • 当前机器中有 id_rsa
  • 远程 github 中已加载 id_rsa.public(settings -> Access -> SSH &GPG keys)

INIT

  • git init
    • 在当前目录下建立 .git 目录
    • clone 的目录在此目录下
git config --global user.name ldscfe
git config --global user.email [email protected]
git config --global color.ui true   # git status等命令自动着色
# git config --list
# 自动判断提交位置(clone多个库)
git config --global push.default matching

Repository

clone 远程仓库

# 需要在当前 repositories 下 settings/Deploy keys 中有相应 RSA publickey
# 客户端中 .ssh 中有相应的 id_rsa
git clone [email protected]:ldscfe/pangolin.git
.-OR-.
# 记录 token: Settings -> Developer Settings -> Personal access tokens -> tokens(classic)
git clone https://<Token Name>:<Token>@github.com/ldscfe/devudefj2.git

刷新

git pull

增加文件

git status           # 查看文件状态

git add $FN
git add .            # 所有

提交

# 需要 git add
git commit -m "comment content"
git push

去除文件&目录

# .gitignore
log/
target/
src/test/
.DS_Store
.gitignore

# 已 git add 的文件,在 .gitignore 中标识无效
git rm -f ${FN}      # 已 git add 的文件,删除后.gitignore 中标识有效

分支

# 分支之间切换、恢复文件、创建新分支等
git checkout <branch-name>           # 从当前分支切换到指定的分支 <branch-name>, 或主分支:master
git checkout -                       # 快速切换回前一个分支
git checkout -- <file>               # 将指定文件 <file> 恢复到最新的提交状态,丢弃所有未提交的更改
git checkout -b <new-branch-name>    # 创建一个新分支 <new-branch-name> 并切换
...
# 推送本地和远程都存在的同名分支
git config --global push.default matching

Creating remote repositories

git remote add ldscfe_cpp [email protected]:ldscfe/cpp.git
git remote add ldscfe_pangolin [email protected]:ldscfe/pangolin.git
git remote add ldscfe_udefpy3 [email protected]:ldscfe/udefpy3.git

#You can use the command git remote set-url to change a remote's URL.
git remote set-url <REMOTE_URL>

Public Effect

settings -> Danger Zone -> Change visibility

  • The code will be visible to everyone who can visit https://github.com
  • Anyone can fork your repository.
  • All push rulesets will be disabled.
  • Your changes will be published as activity.
  • Actions history and logs will be visible to everyone.

Example

DT=`date '+%Y/%m/%d %H:%M:%S'`
git add .
git commit -m "User-defined class libraries, $DT"
git push

之前最好用 git status 确认一下。

Error

RSA 证书无或错误

ERROR: Permission to XXX/XXX.git denied to deploy key
fatal: Could not read from remote repository.
-.OR.-
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
  1. repository 下 settings/Deploy keys 中有相应 RSA publickey
  2. 客户端中 .ssh 中有相应的 id_rsa(MacOS 使用 ssh-add)
  3. 不同的 repository 使用不同的 RSA publickey

分支冲突,本地版本陈旧

Automatic merge failed; fix conflicts and then commit the result.

丢弃本地分支内容

git reset --hard origin/master

首次推送

clone 后,首次 git push 出现:
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch.

未指定推送到哪个分支,一般发生在首次推送。

git push origin master

git init

fatal: Not a git repository (or any of the parent directories): .git

git remote add 时出现,原因:未 git init

repository 不存在或无权限

git pull 时出现:
ssh_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.