git 命令 - 回滚、查看、合并、同步命令收藏
2018-02-07 13:25
239 查看
1 git 回滚
强制回滚远程分支git push -f origin commit_id:master强制放弃本地修改git reset --hard
2 git 合并某一个commit id提交的内容
git cherry-pick 62ecb33 git 查看远程仓库地址
git remote -v4 Git同步原始仓库和Fork仓库
步骤初始化本地仓库
mkdir test-repo
cd test-repo
git init
添加远程仓库地址
添加原始仓库地址,就是被Fork的。
git remote add parent https://github.com/user/test-repo.git 地址是https协议的,不能是ssh协议的,除非有权限。
添加自己远程仓库地址,最好是ssh协议地址。
git remote add origin git@github.com:SeayXu/aspnetcore-doc-cn.git
拉取原始远程仓库到本地
git pull parent master注意:
初始化的仓库默认分支是master,如果你同步下来的分支不是在master分支,需要切换到其他的分支时,需要先提交一下本地仓库,然后再切换。
提交本地仓库
在拉取原始仓库后,可以根据自己需要是否需要本操作。如果拉取后有改动,执行提交操作,否则直接下一步。
git add -A
git commit -m "updated at:$(date '+%Y-%m-%d %H:%M:%S')"
这里为了自动化,后面的提交信息是一串时间。
推送本地仓库到远程仓库
git push origin dev
脚本
为了能不每次都敲这么多命令,可以将这些命令写在shell脚本中。
下面是我的一个示例:
sync.sh#!/bin/bash
echo "change dir..."
cd ../src
echo "dir:`pwd`"
echo -e '\n'
echo "git pull repo from parent..."
git pull parent master
echo "git pull repo from parent complated!"
echo -e '\n'
echo "git commit repo into local..."
git add -A
git commit -m "updated at:$(date '+%Y-%m-%d %H:%M:%S')"
echo "git commit repo into local complated!"
echo -e '\n'
echo "git push repo to origin...!"
git push origin master
echo "git push repo to origin complated!"
5 git合并其他fork分支到本地分支
1) To pull in somebody else's changes, first add a remote that points to their repository. For example:
git remote add soniakeys https://github.com/soniakeys/goptimize.gitThen, you can fetch those changes into your repository (this doesn't change your code, yet):
git fetch soniakeysFinally, to merge those changes, make sure you're on your
masterbranch and:
git merge soniakeys/master2) To be polite, you would normally ask the author whether it's okay to pull the changes. Just because they're on a public repository doesn't necessarily mean they are ready to pull. There might be further work to do, or perhaps intellectual property issues, or whatever. However, with published changes on an open source repository, asking is not strictly required.
6 打patch
diff -Naur 旧的目录 新的目录 > patch文件[1] Rolling back a remote Git repositoryhttps://stackoverflow.com/questions/588414/rolling-back-a-remote-git-repository[2] Git合并特定commits 到另一个分支 http://blog.csdn.net/ybdesire/article/details/42145597
[3] Git同步原始仓库到Fork仓库中
https://www.linuxidc.com/Linux/2016-06/132354.htm
[4] 用Diff和Patch工具维护源码, https://www.ibm.com/developerworks/cn/linux/l-diffp/
git 资料
GitHub 使用教程图文详解 http://www.linuxidc.com/Linux/2014-09/106230.htm Git 标签管理详解 http://www.linuxidc.com/Linux/2014-09/106231.htm Git 分支管理详解 http://www.linuxidc.com/Linux/2014-09/106232.htm Git 远程仓库详解 http://www.linuxidc.com/Linux/2014-09/106233.htm Git 本地仓库(Repository)详解 http://www.linuxidc.com/Linux/2014-09/106234.htm Git 服务器搭建与客户端安装 http://www.linuxidc.com/Linux/2014-05/101830.htm Git 概述 http://www.linuxidc.com/Linux/2014-05/101829.htm 分享实用的GitHub 使用教程 http://www.linuxidc.com/Linux/2014-04/100556.htm Ubuntu下Git服务器的搭建与使用指南 http://www.linuxidc.com/Linux/2015-07/120617.htm相关文章推荐
- git查看远程代码更新,合并到本地分支,以及远程代码的回滚
- git 常用命令(3)- git内容合并和冲突查看
- Git命令之上传与同步
- Git 常用命令(查看历史,……) --持续更新
- Git log命令查看所有的历史版本
- git 分支与合并,常用命令
- git命令查看、创建、切换、删除分支
- git 查看、创建、切换、合并、删除分支
- [版本控制之道] Git 常用的命令总结(欢迎收藏备用)
- DAY23 git命令和idea git操作指南(含分支创建合并)
- git查看和操作commit命令
- Linux下查看设置时间及同步时间的命令
- 轻松使用git命令查看版本记录
- linux查看系统信息的命令[收藏]
- git命令查看远程分支
- git查看远程仓库地址命令
- git 常用命令 创建查看删除分支,创建查看删除tag等
- github学习,新建git、同步项目到github、git常用命令
- git 回滚到上个版本命令以及忽略某些文件提交
- git命令合并分支代码