git常用命令
初始化
git init
拉取远程分支代码
git clone [url]
本地与服务端同步
git pull [remote] [branch]
添加指定文件到暂存区
git add [dir]
本地提交
git commit -m [message]
远程提交
git push [remote] [branch] # remote:origin
查看本地所有分支
git branch
查看远程所有分支
git branch -r
新建一个分支,但依然停留在当前分支
git branch [branch-name]
切换本地分支
git checkout [branch]
新建一个分支,并切换到该分支
git checkout -b [branch]
合并指定分支到当前分支
git merge [branch]
重置暂存区与工作区,与上一次commit保持一致
git reset --hard
重置当前分支的指针为指定commit,同时重置暂存区,但工作区不变
git reset [commit]
重置当前分支的HEAD为指定commit,同时重置暂存区和工作区,与指定commit一致
git reset --hard [commit]
# 添加远程仓库
git remote add origin https://e.coding.net/alenyao/fsj-ali/mod-jtlsp-sync.git
# 删除远程连接
git remote rm origin
# 提交
git push -u origin master
# 把远程分支拉到本地
git fetch origin dev
# 显示修改文件
git status
# 显示修改内容
git diff readme.txt
1.回滚本地代码
git reset --hard 1c4f74feb2381a1835bd6eb0dbb377992505f769
2.覆盖远程代码
git push origin branch-name --force
git push origin develop_zy --force
git push origin develop-new --force
git push origin master-finance --force
3.git标签常用命令
git tag <lightweght_name>:为当前分支所在的提交记录打上轻量标签。
git tag <lightweght_name> <commit SHA-1 value>:为某次具体的提交记录打上轻量标签。
git tag -a <anotated_name> -m <tag_message>:为当前分支所在的提交记录打上附注标签。
git tag:列出所有的标签名。
git tag -d <tag_name>:删除某个标签,本质上就是移除 .git/refs/tags/ 中对应的文件。
git show <tag_name>:显示标签对应提交记录的具体信息。
git push <remote> <tag_name>:推送某个标签到远程仓库。
git push <remote> --tags:推送所有标签到远程仓库。
git push <remote> --delete <tag_name>:删除远程仓库中的某个标签。
4.设置git pull时免登录,在.git/config文件中添加一下配置
[credential]
helper = store