- force reset to the version of the last two 取消当前版本之前的两次提交
git reset --hard HEAD~2
- force push to the remote re 强制提交到远程版本库,从而删除之前的两次提交数据
git push origin HEAD --force
git reset --hard HEAD~2
git push origin HEAD --force
2.clone the git repository 克隆代码至本地
$git clone git@github.com:user-name/repository-name
3.set svn as a remote repository 把svn仓库添加为远程仓库
$git svn init -T http://url/svn/trunk/
4.fetch 获取svn仓库的代码
$git svn fetch
5.show all branch 显示所有分支
$git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master remotes/origin/trunk
remotes/trunk is the svn branch 其中,remotes/trunk为svn分支
6.merge 合并svn分支
$git merge trunk
7.push 推送至github
$git push
git rev-list HEAD --count
git rebase -i HEAD~$x
其中$x代表你期望操作的记录数,小于提交记录数 $x is the count of commit that you want to combine or change, $x is less than commit count
如 e.g.
你想操作最后十条,则$x为10 if you want to change the last ten commits, the value of $x is 10.
pick 123456 init pick 7890ab add text pick cdef12 modify text pick 345678 modify text
change the "pick" that is in front of the commit line to "s", the commit will combine to previous commit. 在你期望合并的commit将前面的pick更改成s就行, 此条commit将于上一条commit合并
change the "pick to "r", the commit message will be modify. pick改成r表示修改当前提交信息
e.g.例如:
"pick 345678 modify text" --> "s 345678 modify text"
# This is a combination of 2 commits. # The first commit's message is: modify text # This is the 2nd commit message: modify text # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # HEAD detached at 8658d47 # You are currently editing a commit while rebasing branch 'master' on 'ddcff57'. # # Changes to be committed: # (use "git reset HEAD^1..." to unstage) # # new file: ignorelist # modified: README.md # # Untracked files: # (use "git add ..." to include in what will be committed) #
change text # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # HEAD detached from 18e598b # You are currently editing a commit while rebasing branch 'master' on 'ddcff57'. # # Changes to be committed: # (use "git reset HEAD^1..." to unstage) # # new file: README.md # # Untracked files: # (use "git add ..." to include in what will be committed) #
git push -f
Create repository 创建库
新建库
可以在任何有权限的账户上创建库,无论是个人或组织帐号
Establish a secure connectio SSH Keys 如果决定不使用推荐的HTTPS方法,也能用SSH keys去建立一个安全的终端到github的链接, 下面的步骤将引导你产生一个SSH key然后加入公钥到github帐号
Repository Configure 库配置
Local Setting 本地配置
git config user.name name 设置用户名 set user name
git config user.email email 设置email地址 set user email
Status 状态查询
git log --oneline --graph 显示日志 show log
git status -s 显示工作区状态 show work box status
Box - Stage 工作区和暂存区
git add -A 加入所有修改至缓存区 add file new file, removing file and motified content to stage
git add -u 加入修改内容至缓存区 update motified content to stage
git rm file 移除文件 remove file from work box and stage
git checkout -- file 从缓存区恢复至工作区 restore file in work box from stage
Stage - Repository 暂存区和库
git reset, git reset HEAD, git reset -- file 用库重置暂存区 restore stage from repository
git diff --cached 比较暂存区和库 compare stage with HEAD(local Repository)
git commit -m 'message' 提交缓存区至库 commit stage to repository
Box - Repository 工作区和库
Repository - Stage - Box
git reset --hard HEAD 用库恢复工作区和暂存区 restore work box and stage from repository
git checkout [commit] -- file 检出至工作区和暂存区 checkout to work box and stage
Repository
git reset --soft HEAD^ 还原至上一版本 revert to last version(HEAD^)
git commit --amend -m 'new comment' modify log 修改版本日志
Local Repository - Remote Repository 本地库和远程库
git clone file://path.name.git 克隆git库 clone git repository
git push 更新远程库 update remote repository
git pull 获取远程库,合并到本地 fetch and merge remote to local
With SubVersioN
svnadmin create git init --bare svn checkout git clone svn update git pull svn revert git reset git checkout -- git [commit] checkout -- svn add git add svn rm git rm svn mv git mv svn diff git diff git diff --cached git diff HEAD svn status git status -s svn commit -m '' git commit -m '';git push svn log git log
保存当前工作进度
git stash save work box to the stash 保存进度
git stash list 显示进度列表 list stash
git stash apply 恢复进度 apply a single stashed state on the top of work box
git stash pop 从进度列表移动某个缓存覆盖工作区 remove a single stashed state and apply it on the top of work box
git stash clear 删除所有存储的进度 clean the stash