您的位置:首页 > 其它

Git常见命令

2017-10-24 15:16 162 查看
1 查看Git版本号

git --version


2 配置

配置用户名:

git config --global user.name "user_name"
git config --global user.email mail.com


查看配置信息:

git config --list


3

新建本地项目:

初始化版本仓库:

git init


添加远程版本库:

git remote add origin git@xxx.git


添加本地代码到仓库:

git add .

说明:

·  git add -A  提交所有变化

·  git add -u  提交被修改(modified)和被删除(deleted)文件,不包括新文件(new)

·  git add .  提交新文件(new)和被修改(modified)文件,不包括被删除(deleted)文件


提交本地代码到仓库:

git commit  -m "message"


推送到远程版本库:

git push -u origin master


查看远程版本:

git remote -v


远程项目

克隆分支:

git clone -b branch_name


删除远程版本库:

git remote rm origin


查看本地分支:

git branch


查看远程分支:

git branch -a


新建本地分支:

git branch branch_name


切换分支:

git checkout branch_name


创建本地分支并且切换到本地分支

git checkout -b local_branch_name


删除本地分支:

git branch -d branch_name


删除远程分支:

git branch -d -r branch_name


重命名分支:

git branch -m | -M oldbranch newbranch

说明:如果newbranch名字分支已经存在,则需要使用-M强制重命名,否则,使用-m进行重命名


推送本地分支到远程

a.远程已有remote_branch_name分支并且已经关联本地分支local_branch_name且本地已经切换到local_branch_name

git push

b.远程已有remote_branch_name分支但未关联本地分支local_branch_name且本地已经切换到local_branch_name

git push -u origin/remote_branch

c.远程没有有remote_branch_name分支并,本地已经切换到local_branch_name

git push origin local_branch:remote_branch_name


附:Idea中,git 删除git文件夹

1、将.idea目录加入ignore清单

echo '.idea' >>.gitignore


2、从Git中删除idea

git rm --cached -r .idea


3、将.gitignore文件加入git

git add .gitignore


4、提交gitiginore文件,将.idea从源代码仓库中删除

git commit -m '(gitignore commit and remove .idea)'


5、push到服务器

git push origin master


6、回滚详见快点我
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息