Git 学习总结

Add

  1. Add the file to the index git add xxx.java
  2. commit the file git commit -m "xxxxx"

Working on a branch

  1. 查看所有branch: git branch
  2. 创建名为xxx的branch: git branch xxx
  3. 从当前的branch换成xxx : git checkout xxx
  4. 创建名为xxx的branch,并换成它: git checkout -b xxx
  5. view the log,查看所有的commits : git log (关闭日志Q+Enter)
    git log -1显示最近一条记录, git log -x显示最近x条

Merge

Fast-Forward merge: 把副branch(它的初始状态是由主branch复制过来的)中相对于主branch中新commit的部分,合并到主branch中。相当于将新的commit复制到主branch里。
Non-Fast-Forward merge:主branch中有新的commit需要merge,在主branch中新创建一个commit,连接主branch和副branch中的最后一个commit。

Conflicts

当两个人修改同个文件的同一部分的时候,将发生冲突。
原文件出现 ===== 表示该文件另一branch的修改
出现>>>>指向另一branch的名字
解决冲突后 git merge --continue
终止整个merge过程 git merge --abort (原文件中将不会出现那些符号,merge之前的文件将会保留)

Rebase

另一种将两个branch的内容合到一起的方式。
Instead of going to the branch that we’d want to merge into, we go to branch with the changes and rebase it to the branch we’d like to update the code with.
not the same commit, but a new commit with the same content as the previous one, with another parent.
相当于主branch中是复制的副branch中的commit,并非在主branch上commit。
出现冲突并解决后,git rebase --continue或直接放弃解决git rebase --abort
不想放弃整个rebase的过程,git rebase --skip

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值