您的位置:首页 > 其它

git常用操作

2018-02-12 11:41 204 查看
1、创建仓库$ git init2、添加修改后的文件到本地库$ git add .3、把文件提交到仓库$ git commit -m "备注"4、本地库和远端库关联git remote add origin [url]5、git修改远程仓库地址可直接改:git remote origin set-url [url]
或先删除后重新关联:git remote rm origin
6、创建develop分支并切换分支git checkout -b develop origin/develop7、上传本地当前分支代码到develop分支git push origin develop8、拉取远端代码git pull9、clone远端代码git clone [url]10、查看所有分支的所有操作记录git reflog11、回退git reset --hard commitid12、删除
暂存区
分支
上的文件, 但本地又需要使用, 只是不希望这个文件被版本控制, 可以使用git rm --cached file_path13、冲突解决方法git stash// 暂存当前状态
git pull
git stash pop// 恢复暂存区和工作区进度14、分支操作创建分支: $ git branch mybranch
切换分支: $ git checkout mybranch
创建并切换分支: $ git checkout -b mybranch15、长期记住密码git config --global credential.helper store16、查看分支关联git branch -vv17、本地分支和远程分支建立联系git branch --set-upstream-to=origin/develop develop18、忽略某个文件的一行代码(例如替换本地app.js里面的localhost:8000成远端test.qingchunpai.net/chunshunzhuxue)1)在工程的根目录下创建/打开一个.gitattributes文件(会被提交到本地或者远程仓库),或者在根目录下创建/.git/info/attributes(不会被提交到本地或者远程仓库)
2)在第一步的文件(两者任选其一)中添加如下,用于定义有内容需要被过滤/忽略的文件:*.js filter=app
3)$ git config --global filter.app.smudge 'sed "s#test.qingchunpai.net/chunshunzhuxue#localhost:8000#g"'
$ git config --global filter.app.clean 'sed "s#localhost:8000#test.qingchunpai.net/chunshunzhuxue#g"'
参考资料:
替换:https://juejin.im/entry/57a4aa7ac4c971005a158662
忽略:https://cnodejs.org/topic/54f854e54e70e4022cd933a5
linux sed命令就是这么简单:https://www.cnblogs.com/wangqiguo/p/6718512.html#_label0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: