hhstore / blog

My Tech Blog: about Mojo / Rust / Golang / Python / Kotlin / Flutter / VueJS / Blockchain etc.
https://github.com/hhstore/blog/issues
278 stars 22 forks source link

Git Pro #74

Open hhstore opened 6 years ago

hhstore commented 6 years ago

git force push:

git branch -m master old-master

git branch -m seotweaks master

git push -f origin master

git push to multi remote branch:

(py36-ceres) ζ git remote -v                                                                                                                                       [aa7d607] 
gitlab  git@gitlab.com:ceres-mirror/exchange-trade-proxy3.git (fetch)
gitlab  git@gitlab.com:ceres-mirror/exchange-trade-proxy3.git (push)

origin  ssh://git@192.168.50.190:20022/Ceres/exchange-trade-proxy3.git (fetch)
origin  git@gitlab.com:ceres-mirror/exchange-trade-proxy3 (push)
origin  git@192.168.50.190:20022/Ceres/exchange-trade-proxy3 (push)

# 添加2个 remote PUSH url: 
git remote set-url --push --add origin git@gitlab.com:ceres-mirror/exchange-trade-proxy3  
# fix ssh:
git remote set-url --push --add origin ssh://git@192.168.50.190:20022/Ceres/exchange-trade-proxy3

# 查看 config 配置:
(py36-ceres) ζ cat .git/config  

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = git@gitlab.com:ceres-mirror/exchange-trade-proxy3.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    # 添加2次, 2个PUSH URL (添加几次, 有几个)
    pushurl = git@gitlab.com:ceres-mirror/exchange-trade-proxy3
    pushurl = ssh://git@192.168.50.190:20022/Ceres/exchange-trade-proxy3
[branch "master"]
    remote = origin
    merge = refs/heads/master
[remote "gitlab"]
    url = git@gitlab.com:ceres-mirror/exchange-trade-proxy3.git
    fetch = +refs/heads/*:refs/remotes/gitlab/*
[remote "gogs"]
    url = ssh://git@192.168.50.190:20022/Ceres/exchange-trade-proxy3.git
    fetch = +refs/heads/*:refs/remotes/gogs/*

# push: 自动推到2个分支上
git push -u origin master  
git push

# push: 特定remote
git push -u gitlab master
hhstore commented 5 years ago

FAQ: fix git errors

1. RPC failed; curl 18 transfer closed with outstanding read data remaining

    error: RPC failed; curl 18 transfer closed with outstanding read data remaining
    fatal: The remote end hung up unexpectedly
    fatal: early EOF
    fatal: index-pack failed
# 解决方式一, 网上大部分解决措施:命令终端输入 
git config --global http.postBuffer 524288000

2. git : Please move or remove them before you can merge

Please move or remove them before you can switch branches.
Aborting

git clean -d -fx

# d  -----删除未被添加到git的路径中的文件
# f  -----强制运行
# x  -----删除忽略文件已经对git来说不识别的文件
hhstore commented 5 years ago

fix git merge conflict:

git rebase:

git checkout master
git pull   

#  把分支重新 rebase master,
 [~/src/go-common] [dm-feed/0508-policy-report]
 git rebase master   

# force push:
 [~/src/go-common] [dm-feed/0508-policy-report]
git push -f origin dm-feed/0508-policy-report:dm-feed/0508-policy-report
hhstore commented 5 years ago

diff branch:

git diff dm-feed/0508-policy-report dm-feed/0508-uat

git 撤销已 commit 的提交:


# 上1个:
git reset --soft HEAD^

# 上1个:
git reset --soft HEAD~1
# 上2个:
git reset --soft HEAD~2

git 合并多个 commit:

git 清空历史 commit:

git checkout --orphan newBranch

git add -A

git commit -am "message"

git branch -D master

git branch -m master

git push -f origin master
hhstore commented 2 years ago

配置 github ssh key:

生成ssh key:


ssh-keygen -t ed25519 -C "your_email@example.com"

添加 ssh key 到 github: