在 git 里,每一个 commit 都带有一个 sha1 的标识,在任何分支,任何状态下,如果你知道这次提交的相关情况,可以将一次 commit merge 过来。
git cherry-pick 2379df
在 git 里,每一个 commit 都带有一个 sha1 的标识,在任何分支,任何状态下,如果你知道这次提交的相关情况,可以将一次 commit merge 过来。
git cherry-pick 2379df
分支里多次提交合并成一个提交
示例
将最近几个(number_of_commits) 提交合并成一个提交
git rebase -i HEAD~[number_of_commits]
然后进入交互式选择
# # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. # # Note that empty commits are commented out
这里先进行 commit 方面的选择,把除去第一行的都改为 squash
pick f7f3f6d changed my name a bit squash 310154e updated README formatting and added blame squash a5f4a0d added cat-file
然后进行 commit msg 的界面,自己写一下合并后的 commit。
分支的 push 强制提交会将本地操作生效
参考:
pro git
查看远端( origin ) 的时候,发现有些分支已经 stale 了
git remote show origin
stale (use 'git remote prune' to remove)
修剪
git remote prune origin
On branch master
Your branch and ‘origin/master’ have diverged,
and have 7 and 8 different commits each, respectively.
处理方法
git rebase origin/master
创建 branch
git branch cat
切换到
git checkout cat
这时HEAD 已经到 cat
在 master 上合并 cat
git merge cat
删除 cat 分支
git branch -d cat
创建分支并切换
git checkout -b admin
建立本地分支 develop
git checkout -b develop
查看本地各分支的最后一次提交
git branch -v
建立远端分支 remote branch
git push origin develop
当另一个人在本地
git pull 的时候,会有提示多了一个分支,但是他本地并没有新建 develop
git branch -r 查看远端分支
检出这个分支
git checkout develop
查看本地和远程分支情况
git remote show origin
删除远端分支
git push origin :develop
删除本地分支,用 -D
git branch -D develop
对于已经删除的 develop 分支, 在本地的 develop 下 git push 后,会提示 Everything up-to-date
git remote show origin
这时要做
git remote prune origin
将远端清理
tag 相当于 commit ,经常用于 release
git tag
git checkout v0.0.1
添加新 tag
git tag -a v0.0.3 -m "version 0.0.3"
推送tag到远端
git push --tags
从 github 上更新代码,用的方式为 https方式。如果 git 客户端 >= 1.7.9,使用如下方式缓存密码
git config --global credential.helper cache
默认缓存 900s( 15 min),设置 1 小时
git config --global credential.helper "cache --timeout=3600"
如果 git 客户端 < 1.7.9 使用命令
git config remote.origin.url https://you:[email protected]/you/example.git
或直接编辑文件 .git/config, 在 username 后加上你的密码
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = https://username:[email protected]/jpuyy/myproxy.git
参考:
http://stackoverflow.com/questions/5343068/is-there-a-way-to-skip-password-typing-when-using-https-github