Git 初步命令

git config  --global user.name  "user",

git config --global user.email "xxx@qq.com"

git init [proj-name]

git status

git diff [file] ;查看文件修改过程。

git log [--pretty=oneline]

git reset --hard HEAD^^^^  //返回到上上一个版本。

git reflog  //记录每次命令

2.增加,删除文件。

git add [dir]:添加文件至暂存区。可以用它开始跟踪新文件,或者把已跟踪的文件放到暂存区,还能用于合并时把有冲突的文件标记为已解决状态等

git add . //添加所有工程件到暂存区。

git add <file1> <file2>....;

git rm --cache -r   <file>: 移除跟踪的文件(夹)。

git rm [file1] [file2]   ;移除文件

git mv [file oldname] [file new] ;修改文件 并将修改文件放到暂存区。

代码递交

git commit -m "message".  提交并备注信息。

git commit <file1> <file2> -m "xxx"

git commit -a ;提交工作区自上次commit之后的变化,直接到仓库区

git commit --amend [file1] [file2] 重做上一次commit,并包括指定文件的新变化 



 分支

 git branch ;l列出本地分支,

git branch -r ;列出远程分支;

git branch -a ;列出本地与远程的分支

 git branch [branch name] or git branch -dr [branch name]  ;建立新分支。

git checkout  [branch name]  /转到分支上。

git checkout - //转到上一个分支

git checkout -b [branch]  新建一个分支,并切换到该分支

 git branch --track [branck] [remote branck];建一个分支,与指定的远程分支建立追踪关系

git branch --set-upstream [branck] [remote branck];建立追踪关系,在现有分支与指定的远程分支之间

git merge [branch] //合并分支到当前分支

git branch -d [branch] //delete a branck

git push origin --delete [branch name] //delete remote branch

git branch -dr [branch]

 git remote add [shortname] [url] //添加远程仓库,指定别名,为以后引用。

git fetch [alias]  //从远程仓库下载新分支与数据.该命令执行完后需要执行 git merge 远程分支到你所在的分支

还可以一次性拉取多个分支的代码:git fetch origin master stable oldstable

git merge [alias]/[branch]  

git push -u origin master ;; 本地仓库内容,推送到远程仓库,推送本地的 master 分支到远程 origin,涉及到远程以及分支,当然也得分开写了。

 

 上传:首先,使用add命令把工作目录中的文件添加到暂存区中;然后,再使用commit命令提交到本地仓库中。最后,再使用push命令推送到远程仓库。

download:第一次需要使用clone命令从远程仓库中克隆一份至本地;之后若是远程仓库有内容更新,可以使用pull拉取新更新的内容至本地。

原文地址:https://www.cnblogs.com/yangjunhe460/p/13679946.html