首页 > 代码库 > git基础命令

git基础命令

git config:
git config -l:查看所有配置信息
git config --global user.name zjd2626
git config --global user.email zjd2626@126.com
git config --global core.editor vim


mkdir cidemo &&cd cidemo
git init :初始化一个git仓库
git status :查看git仓库状态

echo "git test">git.txt
git add git.txt :添加git.txt到暂存区
git commit -m "add git.txt" :提交git.txt到本地仓库

git remote add origin https://github.com/zjd2626/cidemo :添加名为origin的远程仓库
git remote -v :查看远程仓库信息
git push origin master :推送本地master分支到远程仓库

git rm git.txt :删除git.txt

git fetch origin master:获取远程分支到本地master分支
git merge origin master:合并远程分支和本地master分支

git pull origin master:上面2条命令的合并

git log:查看commit日志
git log --oneline:每条记录只显示一行信息

git diff commit_id1 commit_id2 :比较2次提交的区别

git tag tag_name:添加一个本地版本标识
git push origin tag_name: 推送该版本标识到远程仓库

git branch -av :查看本地分支和远程分支详细信息
git branch branch_name:基于当前分支创建分支
git checkout branch_name:切换到branch_name分支
git push origin branch_name:推送branch_name分支到远程

git merge branch_name:合并分支


单个文件版本回退:
git reset commit_id filename
git checkout filename
git commit -am "reset filename"
git push origin master


整个项目回退:
git reset --hard commit_id
git add -a
git commit -am "reset to last version"
git push origin master


git clone https://github.com/zjd2626/cidemo :克隆一个git仓库

git基础命令