远程协助软件:Git的用法 前言项目开发中总会遇到协作。这边记录下协作软件Git的用法一、使用命令处理项目拉取和更新1、Git软件下载链接Git - Downloads2、使用命令拉取和更新Git项目点击右键中的Open Git Base here开启命令控制界面//1、克隆代码拉取---未登录需要登录 git clone git仓库链接https://链接.git //2、拉取远程分支 git pull 远程仓库别名origin 分支master //3、查看文件状态 git status //4、把文件提交到暂存区 //4-1、单个文件 git add 文件名 //4-2、所有修改文件不包括删除的只对添加和修改上传 git add . //4-3、所有改动的文件包括新增和删除 git add -A //5、提交更改 git commit -m 备注信息 //6、推荐本地分支到远程 git push origin 分支名master默认 //7、拉取远程分支 git pull 远程仓库别名origin 分支master //8、切换分支 git checkout 分支名 //9、合并分支 git merge 分支名 //10、创建分支 git branch 分支名 //11、放弃之前提交的分支 git rebase origin/master //12、将本地仓库与远程仓库建立关联的命令 git remote add origin 仓库链接https://链接.git //13、Git的初始化命令用于将当前目录转换为Git仓库 git init //14、创建并切换到新的本地分支 git checkout -b 分支名 //15、取消所有文件的暂存 git reset HEAD -- . //16、撤销修改且恢复到上一个版本 git checkout -- .gitignore3、命令使用顺序//1、拉取代码 //第一次使用需要 git clone git pull origin master git status //2、提交代码 git add . git commit -m 提交 git push origin master //需要放弃上面提交的内容重新提交 git rebase origin/master git pull --rebase git push origin master二、使用图形软件1、Git软件下载链接Git - Downloads2、打开图形界面点击右键中的Open Git GUI here开启命令控制界面3、第三方图形界面3-1、Sourcetree链接Sourcetree | Free Git GUI for Mac and Windows3-2、TortoiseGit链接Download – TortoiseGit – Windows Shell Interface to Git注意1、git的逻辑相当于通过git add 把文件放到暂存文件夹然后通过git push把暂存文件夹中的文件推送到git三、如果需要过滤文件不上传在项目根目录创建.gitignore文件#------------------------- # Operating Specific Junk Files #------------------------- # OS X .DS_Store .AppleDouble .LSOverride # OS X Thumbnails ._* # Windows image file caches Thumbs.db ehthumbs.db Desktop.ini # Recycle Bin used on file shares $RECYCLE.BIN/ # Windows Installer files *.cab *.msi *.msm *.msp # Windows shortcuts *.lnk # Linux *~ # KDE directory preferences .directory # Linux trash folder which might appear on any partition or disk .Trash-* #------------------------- # Environment Files #------------------------- # These should never be under version control, # as it poses a security risk. .env .vagrant Vagrantfile #------------------------- # Temporary Files #------------------------- writable/cache/* !writable/cache/index.html writable/logs/* !writable/logs/index.html writable/session/* !writable/session/index.html writable/uploads/* !writable/uploads/index.html writable/debugbar/* !writable/debugbar/.gitkeep php_errors.log #------------------------- # User Guide Temp Files #------------------------- user_guide_src/build/* user_guide_src/cilexer/build/* user_guide_src/cilexer/dist/* user_guide_src/cilexer/pycilexer.egg-info/* #------------------------- # Test Files #------------------------- tests/coverage* # Dont save phpunit under version control. phpunit #------------------------- # Composer #------------------------- vendor/ #------------------------- # IDE / Development Files #------------------------- # Modules Testing _modules/* # phpenv local config .php-version # Jetbrains editors (PHPStorm, etc) .idea/ *.iml # Netbeans nbproject/ build/ nbbuild/ dist/ nbdist/ nbactions.xml nb-configuration.xml .nb-gradle/ # Sublime Text *.tmlanguage.cache *.tmPreferences.cache *.stTheme.cache *.sublime-workspace *.sublime-project .phpintel /api/ # Visual Studio Code .vscode/ /results/ /phpunit*.xml # 过滤不上传的代码路径 application/config/constants.php application/config/database.php cofsesdata/需要注意如果上次以后文件还是提交了可以根据以下步骤处理//1、检查文件是否已被追踪索引--如果已被跟踪设置了.gitignore也是无效。有输出说明被索引 git ls-files | grep 文件名 //例:git ls-files | grep config.php //2、从索引中移除 //移除单个文件 git rm --cached 文件路径 //移除整个logs目录 git rm -r --cached logs/ //3、然后提交 git add .gitignore git commit -m 修复 .gitignore不再追踪指定文件 //然后git status看看文件还会不会出现 //4、检测是否被忽略 git check-ignore -v 文件路径