git 基本操作
- git全局配置
git config --global user.name "username"
git config --global user.email "email"
# 添加记住用户名和密码文件
git config --global credential.helper store
- git局部配置
git config user.name "username"
git config user.email "email"
# 添加记住用户名和密码文件
git config credential.helper store
# 删除本地记住密码
git config --local --unset credential.helper
- . 修改已配置的信息
git config --replace-all user.name "name"
git config --replace-all user.email "123@qq.com"
- . config 配置有system级别 global(用户级别) 和local(当前仓库)三个 设置先从system->global->local 底层配置会覆盖顶层配置分别使用–system/global/local 可以定位到配置文件
git config
- . 查看系统config
git config --system --list
- . 查看当前用户(global)配置
git config --global --list (全局)
git config --local --list (当前项目)
- . 推送到远程testing 如果远程分支不存在 则创建远程testing分支
git push -u origin testing
- . 查看本地分支
git branch
- . 查看远程分支
git branch -r
- . 查看所有分支
git branch -a
- . 创建本地分支(分支名:dev)
git branch dev
- . 跟踪分支
#设置跟踪:
git branch --set-upstream-to=origin/dev
#取消对master的跟踪:
git branch --unset-upstream master
- . 删除分支
#删除本地分支:
git branch -d dev
#删除远端分支:
git push --delete origin dev
- . 重命名分支
git branch -m oldbranch newbranch
- . 创建分支并切换分支(分支名:dev)
git checkout -b dev origin/dev
- . 切换分支(已有本地分支 分支名:dev)
git checkout dev
- . 将远程主机的最新内容拉到本地,用户在检查了以后决定是否合并到工作本机分支中
注:git pull 则是将远程主机的最新内容拉下来后直接合并,即:git pull = git fetch + git merge,这样可能会产生冲突,需要手动解决。
git fetch
- . 合并分支
注: master(主分支) dev2(常规分支)
- . 撤销上次提交 参考大神文档
- git reset
- git revert
- . 添加远程仓库地址
git config remote.origin.url "https://..."
- . 指定远程仓库地址
git remote set-url origin "https://..."
- . 删除远程长裤地址
git remote rm origin
切换远程分支
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/Release
remotes/origin/master
$ git checkout -b myRelease origin/Release
Branch myRelease set up to track remote branch Release from origin.
Switched to a new branch 'myRelease'
PS: 作用是checkout远程的Release分支,在本地起名为myRelease分支,并切换到本地的myRelase分支
合并分支
合并前要先切回要并入的分支
以下表示要把issue1234分支合并入master分支
$: git checkout master
$: git merge issue1234
Merge made by recursive.
README | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
撤消上一次commit的内容(该操作会彻底回退到某个版本,本地的源码也会变为上一个版本的内容)
git reset --hard <commit-id>
以下表示要撤消“update build gradle configuration file”这一次的commit id,返回到"add battery settings ui"这一次的commit id
xp.chen@YC-JG-YXKF-PC27 MINGW64 /f/ob ((c8303a9...))
$ git log
commit c8303a9e8db2bcf4edb7488e722a380f4e8858ec (HEAD)
Author: xp.chen <xp.chen@yuneec.com>
Date: Sat Oct 28 09:28:51 2017 +0800
update build gradle configuration file
Change-Id: I9ee532fd0d4698613698a64eb754fb98a8559e32
commit 8d8e5ccf24cf6836ab780aa3860270c3876e825a
Author: xp.chen <xp.chen@yuneec.com>
Date: Sat Oct 28 09:02:01 2017 +0800
add battery settigns ui
Change-Id: Ia907ee4e84f54c00a186d31378a7925a6adaba0e
xp.chen@YC-JG-YXKF-PC27 MINGW64 /f/ob ((c8303a9...))
$ git reset --hard 8d8e5ccf24cf6836ab780aa3860270c3876e825a
HEAD is now at 8d8e5cc add battery settigns ui
xp.chen@YC-JG-YXKF-PC27 MINGW64 /f/ob ((8d8e5cc...))
$ git log
commit 8d8e5ccf24cf6836ab780aa3860270c3876e825a (HEAD)
Author: xp.chen <xp.chen@yuneec.com>
Date: Sat Oct 28 09:02:01 2017 +0800
add battery settigns ui
Change-Id: Ia907ee4e84f54c00a186d31378a7925a6adaba0e
git commit -m 注释换行
git commit -m 注释可以通过单引号来换行,比如:
$ git commit -m '
> 1.aaaaa
> 2.bbbb
> '
[master b25154b] 1.aaaaa 2.bbbb
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 ss.txt
通过git commit --amend 命令可以查看到刚刚的log信息为
1.aaaaa
2.bbbb
244



被折叠的 条评论
为什么被折叠?



