前言:git命令有很多,不是每个都记得住,在此记录,方便查询。

 

其他GitHub在8.13不能使用的问题解决

使用GitHub客户端。

1,在客户端。ssh-keygen -t rsa -C "xx@yy.com" 

2,在GitHub设置上添加pub公钥。

 

 

 

四、Git配置和账户相关 

(1)切换账号

1. 查看当前登录账号:

git config user.name

2. 查看当前登录邮箱:

git config user.email

3. 修改用户名和邮箱:

git config --global user.name "Your_username"
git config --global user.email "Your_email"

 

(2)在docker中git pull遇到这个问题

hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint:
hint: git config pull.rebase false # merge (the default strategy)
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.

解决办法:

git config --global pull.rebase false # 这将保留默认行为并禁止显示警告。

https://www.cnblogs.com/hongdada/p/9549506.html

 

三、撤销相关

(1)撤销commit

git reset --soft HEAD^

参考:https://www.jianshu.com/p/a9f327da3562

 

(2)删除本地文件,并commit了,想恢复

git restore --staged src/components  # 撤销commit

git checkout . # 恢复文件到本地

 

(3)关于回退到某一个历史版本(commit)

git reset --hard 3b6be5ef353440718c4129ac84f66fd6052f1c2

注意:上述命令执行成功之后,会彻底返回到回退前的版本状态,新发生的变更将会丢失。对于部分发生了变更,但是变更部分的文件夹存在未提交的文件可能导致目录非空而删除失败,此时需要自行处置。

 

二者区别:

git reset –-soft:回退到某个版本,只回退了commit的信息,不会恢复到index file一级。如果还要提交,直接commit即可;
git reset -–hard:彻底回退到某个版本,本地的源码也会变为上一个版本的内容,撤销的commit中所包含的更改被冲掉;

初始状态,可见当前分支最后一个提交是debug the initialization page

现在要撤销该commit,但是又不能撤销该提交包含的更改,使用git reset --soft,执行结果为

可见commit取消了,代码更改并没有取消。

参考:https://blog.csdn.net/yangfengjueqi/article/details/61668381

 

 

二、关于远程操作

(1)删除远程分支:

先查看远程分支:git branch -r

使用下面两条命令来删除远程分支

git branch -r -d origin/branch-name
git push origin :branch-name

参数含义: -r, --remotes List or delete (if used with -d) the remote-tracking branches.

上面的第一句是删除了本地的远程跟踪分支( 我也不知道怎么描述更加清楚),此时使用git branch -a查看,分支remotes/origin/branch-name应该已经不存在了。

为什么还需要第二句,因为上面只是把本地的远程跟踪分支删除了,远程的分支还没有删除,所以第二句就是真正的删除原种分支。

若出现错误  重新操作  

Pushing an empty <src> allows you to delete the <dst> ref from the remote repository.

 

(2)更改GitHub远程仓库源

git remote rm origin

git remote add origin NewGitURL

参考:https://www.cnblogs.com/x9mars/p/12391095.html

 

(3)GitHub删除tag

GitHub界面上没权限

git push origin --delete v0.16.2

 

一、Git最基本用法

(1)git 开新分支:

想基于某一个分支切新分支:就先到该分支下,运行命令git checkout -b即可。
git checkout okexchain/branchA
git checkout -b okexchain/branchB

 

(2)更换主分支:由main改为master。(在GitHub上遇到)

git branch -m main master
git fetch origin
git branch -u origin/master master

 

相关文章:

  • 2021-08-15
  • 2021-09-29
  • 2021-06-11
  • 2021-10-19
  • 2022-02-23
  • 2022-02-10
猜你喜欢
  • 2021-09-23
  • 2021-08-21
  • 2022-12-23
  • 2021-09-18
  • 2021-06-01
  • 2021-07-20
相关资源
相似解决方案