您的位置:首页 > 其它

Git使用参考

2016-03-04 00:49 381 查看


git --bare init 建立远端裸仓库

git add . 或 git add xx_目录 xx_文件

git rm . 或 git rm -r xx_目录 或 git rm xx_文件

git commit -m "init xx_工程名" 提交

git remote add origin doom@doomserver:/home/git/project.git 仓库命名

git status 查看文件是否变化

git log 查看提交记录

git clean -df 清除

git checkout file_name 恢复某个已修改的文件,撤销未提交的修改

git revert HEAD 还原最近一次提交的修改

git revert SHA

git reset --hard HEAD~1 将倒数第一次提交删除

git push -u origin new_branch 将本地分支new_branch push到服务器 the '-u' means you want to keep the two branches(remote and local) in sync.

git push origin new_branch:remote_branch 提交分支数据到远程服务器

git push origin :remote_branch 删除远程分支remote_branch

git fetch origin remote_branch:new_branch 从远程获取最新版本到本地,不会自动merge

git fetch origin 同步远程分支到本地 (可同步所有分支)

git fetch -p 删除远程分支后,同步到本地

git branch new_branch 创建分支new_branch

git checkout new_branch 切换到分支new_branch

* git stash 将分支所有修改暂存

* git stash list 查看stash队列

* git stash clear 清空stash队列,删除所有stash

* git stash apply stash@{num} 恢复原先工作内容,不在stash队列删除,num是要恢复的工作现场的编号

* git stash pop stash@{num} 恢复原先工作内容

* git stash drop <id> 删除某一个stash

git checkout -b new_branch 创建并切换到分支new_branch

git checkout -b remote_branch origin/remote_branch 从远程分支创建一个本地同名分支

git checkout --track origin/remote_branch Work on a branch that someone else created

若是本地新建分支,push到服务器后,本地还需要做如下操作,不然git pull会失败:

git branch --set-upstream doom origin/doom # Branch doom set up to track remote branch doom from origin.

git branch -d new_branch 删除分支,要求分支所有修改已经合并到当前分支

git branch -D new_branch 直接删除分支,未合并的代码被丢弃

git branch 查询本地分支

git branch -r 查询远程分支

git branch -a 查询所有分支

git branch -m old_branch new_branch 重命名分支

【merge示例】分支合并

git checkout master

git merge new_branch # Merge new_branch to master

【cherry-pick示例】将已经提交的commit 从一个分支提交到另一个分支

git checkout new_branch

git cherry-pick SHA

【Stash示例】

git add . # 将所有改动加到staging area

git stash # 回复到改动之前

git stash apply

【出现stash栈时】

git stash list

git stash apply@{1}

git stash pop@{1}


git创建与管理远程分支

/article/9196097.html


Git 常用命令速查表(三)

http://blog.csdn.net/ithomer/article/details/7529841
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: