常用git命令(包含从一个远程仓库拉取更新同步到另外一个远程仓库)

创建分支
git branch test

把分支推到远程分支
git push origin test:master         // 提交本地test分支 作为 远程的master分支
git push origin test:test              // 提交本地test分支作为远程的test分支

查看本地分支
git branch

切换分支到test
git checkout test

切换到之前提交的log(commit 69ad395df31468bdc062ab7b4c623cf40c6df4ce)上
git checkout 69ad395df

删除本地分支test
git branch -d test

删除远程分支  
git branch -r -d origin/branch-name
git push origin :branch-name
git remote remove br-name

获取远程分支信息
git remote show (remote-br)


将当前master中的内容提交到另外一个远程分支

git remote add branch1 https://xxx.git

git fetch branch1

git merge branch1/master

git push branch1 master

从一个远程仓库拉取更新同步到另外一个远程仓库。一个典型应用场景是,我fork了一个RTT到我的git下,然后从我的远程仓库中git clone到了本地。一段时间之后,RTT官方的git上有了更新,如何把RTT官方git上的更新同步到我的远程git上?就利用上面的命令,首先在本地git命令中用git remote add增加一个分支来跟踪RTT官方的git,然后把RTT官方的更新git fetch下来,再然后用git merge合并到本地的master分支上,最后用git push提交到自己的远程git上。



把分支"branchname"合并到了当前分支里面
git merge branchname
如果有冲突,在有问题的文件上会有冲突标记,在你手动解决完冲突后就可以把此文件添 加到索引(index)中去,用git commit命令来提交,就像平时修改了一个文件 一样。

将其它分支多个commit合并到当前分支的一个commit
git merge --squash another
git commit -m "message here"
--squash 选项的含义是:本地文件内容与不使用该选项的合并结果相同,但是不提交、不移动HEAD,因此需要一条额外的commit命令。其效果相当于将another分支上的多个commit合并成一个,放在当前分支上,原来的commit历史则没有拿过来。

打标签
git tag -a v1.4
共享标签到服务器
git push origin --tags

放弃当前目录的所以修改
git checkout .

git查看某个文件的修改历史
先切换到文件所在目录,如
cd packages/apps/Mms/src/com/android/mms/ui/
然后使用以下命令之一
Git log -p filename
查看文件的每一个详细的历史修改,如果没有-p选项,只显示提交记录,不显示文件内容修改,git log -p -3 filename 显示最近的3次提交。
git log --pretty=oneline filename
每一行显示一个提交,先显示哈希码,再显示提交说明。
git blame filename
查看文件的每一行是哪个提交最后修改的。

猜你喜欢

转载自blog.csdn.net/caogos/article/details/78261008