从本地建立仓库到服务器:
git init
git add .
git commit -m ""
git remote add origin <branch>
git remote -v
git push origin <branch>
每次新建一个迭代任务: 从master下拉取新分支
git checkout master
git pull
git checkout -b <branch>
git push origin <branch>
git add .
git commit -m
git push origin <branch>
关于git pull 和 git fetch 和 git rebase
git pull === git fetch + git merge
git pull
git fetch: 下载远程与本地不同的部分
git pull: 将远程与本地不同的部分合并到当前分支
git rebase <branch>: 把当前所在分支的HEAD复制提交到branch下
git rebase:
1. 重新补充一系列的提交记录,“复制”它们,然后在另外一个地方逐个的放下去。
有点像git merge 但是效果上看起来就是在当前分支上的一个新的提交.
2. 我们可以使用 rebase -i 对提交记录进行重新排序: git rebase -i HEAD~2
然后使用git commit
提交树上的移动:
HEAD 总是指向当前分支上最近一次提交记录
查看HEAD指向: cat .git/HEAD 或者 git symbolic-ref HEAD
如果想让HEAD指向的不是分支名而是提交记录需要分离HEAD: git checkout <commit>
查看提交记录: git log
使用 ^ 向上移动 1 个提交记录: git checkout <branch>^ 或者 git checkout HEAD^
使用 ~<num> 向上移动多个提交记录,如 ~3: git checkout <branch>~2 或者 git checkout HEAD~2
可以直接使用 -f 选项让分支指向另一个提交: git branch -f <branch> HEAD~3
// 让<branch>指向HEAD~3的位置
撤销变更:
本地撤销: git reset: 通过把分支记录回退几个提交记录来实现撤销改动。
但是这种“改写历史”的方法对大家一起使用的远程分支是无效的哦
远程撤销: git revert: 撤销更改并分享给别人
其他:
修改远程分支: git remote set-url origin [url]
将提交commit1,commit2,commit?复制到当前分支作为新的提交: git cherry-pick <commit1> <commit2> <commit?>