常用命令

git --version
git status
git status --short
git add .\note.md
git add --all
git log
git log --oneline
git branch hello-world-images
git branch

the -a option to see all local and remote branches

git branch -a

Deleted branch emergency-fix

git branch -d emergency-fix

Switched to branch ‘hello-world-images’

git checkout hello-world-images
git checkout -b emergency-fix
git merge emergency-fix

git revert 撤销某次操作,此次操作之前和之后的commit和history都会保留,并且把这次撤销,作为一次最新的提交。
git revert是用一次新的commit来回滚之前的commit,git reset是直接删除指定的commit

ssh -T git@github.com
git pull --all

stage 和stash

Stage Changes相当于git add xxx。可以多选,批量地将变更文件放入暂存区,比git add .好用。
Stash Changes相当于git stash,将选中的变更文件“藏起来”,然后当前分支就“干净”了,可以切换到其他分支去了。
那么藏起来的内容怎么恢复呢?
回到刚才执行git stash的分支,执行git stash pop,就会将最近一次藏起来的内容提取出来了。

注:如果stash了好几次,要提取其中某一次的内容,可以先使用git stash list拿到stash列表,找到那次的index,然后执行git stash apply [index]命令提取出那一次存放的变更内容)

添加远程仓库

git clone https://github.com/LookSeeWatch/GardenerOS.git
git remote add LookSeeWatch-GardenerOS https://github.com/LookSeeWatch/GardenerOS.git

(输入token)

git push LookSeeWatch-GardenerOS
git commit -m "实验1"
git checkout -b shiYan1
git branch -D master

报错

warning: in the working copy of ‘xxx’, LF will be replaced by CRLF the next time Git touches it

git config --global core.autocrlf true

ssh: connect to host github.com port 22: Connection timed out

修改.ssh 文件夹下面的 config 文件

Host github.com
HostName ssh.github.com  # 这是最重要的部分
User git
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa

git进行 push 时:Please make sure you have the correct access rights and the repository exists

解决办法:

1.进入仓库路径

git config --global user.name "yourname"
git config --global user.email "your@email.com"

2.删除.ssh 文件夹(直接搜索该文件夹)下的 known_hosts(手动删除即可,不需要 git)

3.再次 git bash

ssh-keygen -t rsa -C "your@email.com"

4.复制id_rsa.pub到 github 的 ssh Keys 中

5.测试一下

ssh -T git@github.com

6.退出,然后重新进

pycharm 提交代码出现错误 remote: [31mx-oauth-basic: Incorrect username or password (access token)

解决办法:

  • 第一步:控制台输入
git config --system --unset credential.helper
  • 第二步:重启 pycharm