Git 常用命令

本文详细介绍Git的工作流程,包括远程地址连接、本地代码提交、分支操作、冲突解决等核心内容,并深入探讨Git的短命令、commit信息合并、cherry-pick及stash清理等高级技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

Git有3个区,work,head,origin;工作流是将work的代码添加到head中,再由head中堆到origin中

一、远程Git地址连接

git remote -v 查看远程地址

git remote add origin [address] 
eg:git remote add origin scutech -gitoite:xingjun/jdbc_learning.git 添加远程地址

二、提交本地代码

git status 查看Git状态

git add 将work中的内容添加到head中 ./ 代表添加全部

git commit -m "message" 提交设置提交信息

git push -u origin [branch name] 
eg: git push -u origin develop 将Head中的代码堆到远程服务器中

三、分支操作

git -flow init 安装git-flow,第一次需要初始化,后面不需要

git flow feature start [new branch name] 创建一个分支,默认有个feature

git branch 查看分支

git branch [branch name] 创建一个分支

git checkout [branch] 却换分支

git pull 将远程代码拉到本地

修改branch name https://multiplestates.wordpress.com/2015/02/05/rename-a-local-and-remote-branch-in-git/

四、冲突解决

git checkout develop 切换到需要合并到的那个分支(例如:需要将feature中的代码提交到develop产生了冲突)

git pull 将最近代码拉到develop分支中,处理冲突代码

git checkout feature/.. 切换会feature分支

git rebase develop 变基,将feature的基本变更到develop最新的地方

git fetch 查看其他人有没有提交代码

git push origin feature/... 把head中的代码提交到远程中去,有错就7

git push origin feature/... -f 强制提交代码,见下面3中强制提交代码的情况

强制提交代码的情况

       1、自己修改了commit

       2、别人提交了代码

       3、rebase 变基

五、Git短命令(别名)

1、系统短命令

vi ~/.bashrc 在some more ls aliases

2、git短命令

git config --global alias.st "status" 将status别名为st

vi ~/.gitconfig

六、合并commit信息 (git commit -m "Fixed #1233: message")

git rebase develop -i 进入vim模式进行修改 设置git 默认vim : git config --global core.editor "vim"

# p, pick = use commit

# r, reword = use commit, but edit the commit message

# e, edit = use commit, but stop for amending

# s, squash = use commit, but meld into previous commit

# f, fixup = like "squash", but discard this commit's log message 一般用f,合并到前一条pick请求中

# x, exec = run command (the rest of the line) using shell

# d, drop = remove commit

合并失败,中止rebase

git rebase --abort

七、储藏与清理 stash

git stash 将work中的内容保存到栈中

git stash pop 将栈中的内容pop到work中

https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E5%82%A8%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86

八、cherry-pick

对已经存在的commit再次提交

git cherry-pick #id

http://blog.youkuaiyun.com/wh_19910525/article/details/7554430

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值