git概论
感謝:http://www.cnblogs.com/atyou/archive/2013/03/11/2953579.html
git,一個非常強大的版本管理工具。Github則是一個基于Git的日益流行的開源項目托管庫。Git與svn的最大區別是,它的使用流程不需要聯機,可以先將對代碼的修改,評論,保存在本機。等上網之后,再實時推送過去。同時它創建分支與合并分支更容易,推送速度也更快,配合Github提交需求也更容易。
?
Git全局設置
git config --global user.name "Your Name" git config --global user.email youremail@email.com將Git項目與Github建立聯系
mkdir yourgithubproject cd yourgithubproject git init touch README git add README git commit -m 'first commit' git remote add origin git@github.com:yourgithubname/yourgithubproject.git git push origin master導入現有的Git倉庫
cd existing_git_repo git remote add origin git@github.com:yourgithubname/yourgithubproject.git git push origin mastergit最主要的命令
add Add file contents to the index bisect Find by binary search the change that introduced a bug branch List, create, or delete branches checkout Checkout a branch or paths to the working tree clone Clone a repository into a new directory commit Record changes to the repository diff Show changes between commits, commit and working tree, etc fetch Download objects and refs from another repository grep Print lines matching a pattern init Create an empty git repository or reinitialize an existing one log Show commit logs merge Join two or more development histories together mv Move or rename a file, a directory, or a symlink pull Fetch from and merge with another repository or a local branch push Update remote refs along with associated objects rebase Forward-port local commits to the updated upstream head reset Reset current HEAD to the specified state rm Remove files from the working tree and from the index show Show various types of objects status Show the working tree status tag Create, list, delete or verify a tag object signed with GPG日常提交常用命令
git add . git commit -a -m"some files" git push yourgithubprojectgit init
創建一個數據庫。
git clone
復制一個數據到指定文件夾
git add 和 git commit
把想提交的文件add上,然后commit這些文件到本地數據庫。
git pull
從服務器下載數據庫,并跟自己的數據庫合并。
git fetch
從服務器下載數據庫,并放到新分支,不跟自己的數據庫合并。
git whatchanged
查看兩個分支的變化。
git branch
創建分支,查看分支,刪除分支
git checkout
切換分支
git merge
合并分支,把目標分支合并到當前分支
git config
配置相關信息,例如email和name
git log
查看版本歷史
git show
查看版本號對應版本的歷史。如果參數是HEAD查看最新版本。
git tag
標定版本號。
git reset
恢復到之前的版本
----mixed 是 git-reset 的默認選項,它的作用是重置索引內容,將其定位到指定的項目版本,而不改變你的工作樹中的所有內容,只是提示你有哪些文件還未更新。
--soft 選項既不觸動索引的位置,也不改變工作樹中的任何內容。該選項會保留你在工作樹中的所有更新并使之處于待提交狀態。相當于再--mixed基礎上加上git add .
--hard 把整個目錄還原到一個版本,包括所有文件。
git push
向其他數據庫推送自己的數據庫。
git status
顯示當前的狀態。
git mv
重命名文件或者文件夾。
git rm
刪除文件或者文件夾。
git help
查看幫助,還有幾個無關緊要的命令,請自己查看幫助
github網上參與項目協作
?幫助參考官方文檔:https://help.github.com/articles/fork-a-repo
1.A賬號登錄github上,參與B賬號的項目,在B賬號網頁上點fork
2.把項目clone到本地
git clone https://github.com/A/xxx.git
3.添加上游遠端GIT
git remote add upstream https://github.com/B/xxx.git
upstream可以隨便取別名
4.取遠端最新代碼,保證自己的代碼是最新,免得跟別人的有沖突
git fetch upstream
5.合并到本地
git merge upstream/master
6.更新遠端自己的代碼庫(push Update remote refs along with associated objects)
git push?
7.登錄自己的賬號A,在上面點pull request
https://github.com/A/xxx
?
?轉載于:https://www.cnblogs.com/kimsimple/p/7623045.html
總結
- 上一篇: MySQL整理(三)
- 下一篇: 普及组模板——线性筛素数