sourcetree 及git版本工具使用

本文介绍了Sourcetree中重置本地修改的方法,解决分支冲突的步骤,以及Git的基础知识,包括Git的仓库和区域概念,常用命令解析。此外,还讲解了Git submodule的添加、初始化和更新操作,以及如何找回误删的commit。

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

1. 如何reset自己本地的修改?

选中指定的返回版本,右键菜单选择“reset  to this commit”, 然后选择hard 模式。


2. 如何解决两个分支间的conflict?

1. merge develop 到feature,首先merge A 到 B,修改conflict,然后提交。

2. merge feature 到develop,首先merge develop到feature,解决conflict问题,然后pull request,merge feature 到 develop


经典git教程:

http://git-scm.com/book/zh/v1

http://www.ruanyifeng.com/blog/2012/07/git.html

git 架构

git会有两个仓库,一个是remote repository,再远程服务器上,一个是local repository

git的三个区域:

remote repo  ---------------  local repo ----------------- local work area

git fetch 从remote repo 到 local repo

git checkout : 从local repo 到 local work area,切换工作区域和local repo的分支

git pull : 从remote repo 拉到 local repo 和 local work area.


git  一些常用命令,及区别

git branch 创建分支

git checkout 创建或切换分支

git fetch 将服务器的文件同步到本机器的服务器分支


git pull = git fetch + git merge to local

git reset --hard HEAD 将work area版本指向本地的最新版本。


典型的更新流程:

git checkout master                                                  
git fetch                                        
git diff origin/master
git pull --rebase origin master

git add 添加文件


提交本地修改,并merge到本地的master分支

git commit 
git checkout master 
git merge branchname 

提交到远程master分支
git push origin master:master


===============================

// 添加Git submodule仓库
git submodule add <remote_url> <local_path>

// 对于clone一个有submodule的仓库,是不会把submodule也clone下来
// 需要额外的步骤:
// 1. 注册submodule到.git/config里
git submodule init
// 2. clone submodule
git submodule update --recursive
// 上面两步等价于下面
git submodule update --init --recursive

// 如果修改了.gitmodule的remote url,使用下面的命令更新submodule的remote url
git submodule sync


如何更新module 子模组?

1. 先到子模组目录,git checkout master,git pull 更新同步 子模组

2. 再到父repo,查看状态git status,子模组更新状态会留在 super-repo

3. 提交子模组状态 git commit...


================

绝招:

如何找回误删的commit,包括hard reset模式?

1. git reflog   // 找出近期所有的commit,包括误删的commit, reflog里包含了HEAD的修改记录

2. git show  xxxx // 显示对应commit的一些详细信息, 或者使用 git log -g可以查看reflog中的详细内容

3. git branch .... xxxx // 将对应的commit,拉出一个分支....进行处理

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值