Git命令

Git 命令分类整理

      • git 基础命令
      • git 冲突解决
      • git pull = git fetch + git merge
      • git rebase 和 git merge
      • git cherry-pick
      • git 恢复之前版本的两种方法reset、revert
    • C:\Users\root\.ssh\config
    • 代码库迁移

git 基础命令

# 将远程分支切到本地  并起名
git checkout -b local_name origin/xxx

git checkout

# aaa分支与当前分支merge
git merge aaa

# 查看本地和远程的对应关系
git branch -vv

# 在gitlab里删除了分支branch_a,本地输入git pull然后git branch -a依然可以看到remotes/origin/branch_a。请问如何在远程删除这个分支。
git fetch -p

git branch -d 删除分支


git commit

git log -2 
1. git log 查看提交历史记录
2. git log --oneline 或者 git log --pretty=oneline 以精简模式显示
3. git log --graph 以图形模式显示

git show commitId


# git本地分支提交到远程指定的分支
git push origin lx_dev_neutron_api:dev_neutron_api
git push origin HEAD:dev_neutron_api
# push完可以 git diff 比较一下两个分支的区别:
git diff local_feature_xxx origin/remote_feature_xxx


git pull = git fetch  +  git merge

git fetch 

# 自己本地分支local合代码到远程develop步骤:
1 local  git pull
1 git checkout develop , git pull
2 git checkout - , git merge develop   切回自己本地local再把develop merge到自己本地
3 解决冲突 git add -u   ,git rebase --continue
4 git push 到loacl对应的远程分支
5 在gitlab界面进行合入


git push origin --delete Chapater6

# 删除本地分支

git 冲突解决

# step1 在本地仓库中, 更新并合并代码
git fetch origin
git rebase origin/master

# step2 依据提示分别打开冲突的文件, 逐一修改冲突代码

# step3 所有冲突都修改完毕后, 提交修改的代码
git add -u
git rebase --continue

# step4 更新patch
git push origin HEAD:refs/for/master

git pull = git fetch + git merge

git rebase 和 git merge

git merge 与 git rebase的区别

https://blog.csdn.net/zhouyan8603/article/details/105281104

git cherry-pick

cherry-pick

对于多分支的代码库,将代码从一个分支转移到另一个分支是常见需求。

这时分两种情况。

一种情况是,你需要另一个分支的所有代码变动,那么就采用合并(git merge)。

另一种情况是,你只需要部分代码变动(某几个提交),这时可以采用 Cherry pick。

git 恢复之前版本的两种方法reset、revert

Git恢复之前版本的两种方法reset、revert(图文详解)

C:\Users\root.ssh\config

# https://www.cnblogs.com/southday/p/10011261.html
# https://www.dabu.info/github-gitlab-mutiple-ssh-key-config.html


# git clone时候
# 不需要配置
# git config --global user.name xxx
# git config --global user.email [email protected]
# 可以直接clone 
# git clone [email protected]:olle/ranu.git
# git clone ssh://[email protected]:8641/newrt/backend.git
# 配置git config --global user.name xxx 以后【公司代码】可以直接push

# 【appium代码】 git push 时候要配置name 和 email 或者临时使用
# git config user.name xxxx
# git config user.email [email protected]

###################################################
# gitee          [自己 gitee]
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile /c/Users/root/.ssh/id_rsa_gitee

# github account [自己 github]
Host github.com
	HostName github.com
	User xxxx
	IdentityFile /c/Users/root/.ssh/id_ed25519
	IdentitiesOnly yes
	
# github account [自己 github 账户2 现在没有该账户]
Host github.com
	HostName github.com
	User xxxx_222
	IdentityFile /c/Users/root/.ssh/id_ed25519_2
	IdentitiesOnly yes

# gitlab account [公司 gitlab]
Host gitlab.yun.cn # 可不填
    # 公司的gitlab域名
	HostName gitlab.yun.cn
	#User xxxx
	IdentityFile /c/Users/root/.ssh/id_devops
	IdentitiesOnly yes
	
# gitlab account [兴趣项目 gitlab]
# 如果是自建的gitlab,则hostName设置为ip,Port设置为端口号,若是默认ssh端口,则可以省略端口。
Host 114.113.114.222
	HostName 114.113.114.222
	#Port 8641           # port 不写也行
	#User xxxx
	IdentityFile /c/Users/root/.ssh/id_rsa_appium
	IdentitiesOnly yes

代码库迁移

https://my.oschina.net/jingshishengxu/blog/4287916

删掉旧仓库 重新clone一次
git clone [email protected]:controller/feitian.git

cd feitian/

git branch

git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done

git fetch --all

git pull --all

git branch

git remote rename origin old-origin

git remote add origin [email protected]:cnp/tiantian.git

git push -u origin --all

git push -u origin --tags

#git remote set-url origin gitlab@新仓库IP:仓库路径.git
#git push --all origin//推送所有分支
#git push –-tags     //推送所有tags 或者 git push  --follow-tags

你可能感兴趣的:(git,git)