git 浣跨敤閭d簺浜嬪効
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了git 浣跨敤閭d簺浜嬪効相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e5%8d%8f%e8%ae%ae' title='鍗忚'>鍗忚
under 浠g爜 shell 鐐瑰嚮 淇敼 free commit 缃戞槗鏈枃鏉ヨ嚜缃戞槗浜戠ぞ鍖?/p>
浣滆€咃細瀛欐湁鍐?/p>
宸ユ鍠勫叾浜嬶紝蹇呭厛鍒╁叾鍣紝git鏄竴涓紑婧愮殑鍒嗗竷寮忕増鏈帶鍒跺伐鍏?寰堝鏂囩珷閮藉啓鐨勫お闀匡紝鎴栬€呰祫鏂欏お澶氾紝闅句互涓€鏃堕棿鐪嬪畬銆傚湪姝ゆ€荤粨浜唃it鐨勪竴浜涗娇鐢ㄦ柟寮忥紝鍥犳璇ユ枃涓嶆槸楦跨瘒宸ㄨ憲锛屼絾鏄鏋滅湅瀹屼篃搴旇鍙互涓婃墜鎿嶄綔浜嗐€?/p>
git 瀹夎涓庨厤缃?/h2>
瀹夎
Linux: shell 鐣岄潰杈撳叆锛?nbsp;sudo apt-get install git-core 鍥炶溅杈撳叆瀵嗙爜Windows锛歔涓嬭浇瀹夎鍖匽(https://github.com/git-for-windows/git/releases/tag/v2.6.3.windows.1>) 涓嬭浇瀵瑰簲鐨別xe瀹夎鍖咃紝鍙屽嚮瀹夎 Mac锛歵erminal : brew install git
閰嶇疆鍏ㄥ眬鐢ㄦ埛鍚嶅拰閭锛孡inux: shell 锛學indows: Git Bash 锛孧ac:terminal 鍛戒护濡備笅锛?/p>
git config --global user.name 鈥渨akaka" /user.email "[email protected]鈥?/pre>鏌ョ湅鏄惁閰嶇疆鎴愬姛锛?/p>
git config --global user.name / user.email鍒涘缓浠g爜浠撳簱锛圧epository锛?/h2>
浠撳簱鏄敤浜庝繚瀛樼増鏈鐞嗘墍闇€淇℃伅鐨勫湴鏂?鎵€鏈夋湰鍦版彁浜ょ殑浠g爜閮戒細琚彁浜ゅ埌浠撳簱涓紝涔熷彲浠ユ帹閫佸埌杩滅▼浠撳簱涓€傛瘮濡傛湰鍦版湁涓€涓狣emo椤圭洰锛宑d杩涘叆Demo鐩綍銆傝緭鍏it init锛岀洰褰曚笅浼氱敓鎴愰殣钘忕殑.git鏂囦欢澶癸紝濡傛灉瑕佸垹闄や粨搴擄紝鍒犻櫎璇ユ枃浠跺す銆?/p>
git鍛戒护
add锛氭妸瑕佹彁浜ょ殑浠g爜娣诲姞杩涙潵锛屽彲浠ヨ涓哄埌涓€涓紦鍐蹭腑[閲嶈]
鎻愪氦鏂囦欢test.java 锛歡it add test.java 鎻愪氦鐩綍test 锛歡it add test 鎻愪氦鎵€鏈夋枃浠讹細 git add .commit锛歛dd瀹屾垚鍚庯紝鐪熸鐨勪唬鐮佹彁浜閲嶈]
git commit -m 鈥渃ommit鈥?nbsp;// -m 鎻忚堪淇℃伅锛屼笉鑳戒负绌?/pre>.gitignore: git浼氭鏌ユ槸鍚﹀瓨鍦ㄨ鏂囦欢锛屽瓨鍦ㄥ氨璇诲彇璇ユ枃浠跺唴瀹癸紝灏嗛厤缃枃浠舵垨鑰呯洰褰曟帓闄ゅ湪鐗堟湰涔嬪锛屾枃浠跺拰鐩綍鍙互浣跨敤鈥?鈥濋€氶厤绗︺€傚彲浠ユ墜鍔ㄥ垱寤哄湪鏂囦欢銆?/p>
TestA.java // 鎺掗櫎璇ユ枃浠秚estDir // 鎺掗櫎璇ョ洰褰?/pre>status: 鏌ョ湅涓婃鎻愪氦鍚庢枃浠朵慨鏀圭殑鍒楄〃
git statusdiff锛氭煡鐪嬫枃浠朵慨鏀圭殑鍐呭锛?鍙蜂唬琛ㄥ垹闄ら儴鍒嗭紝+鍙蜂唬琛ㄦ坊鍔犻儴鍒?/p>
git diff TestB.java // 鏌ョ湅TestB.java淇敼鐨勫唴瀹?/pre>checkout锛氭挙閿€鏈彁浜ょ殑淇敼锛堟湭鎵цadd鎿嶄綔锛?/p>
git checkout TestB.java // 鎾ら攢TestB.java鐨勪慨鏀?/pre>reset锛氬彇娑坅dd鐘舵€?/p>
git reset HEAD TestB.java // 鍙栨秷TestB.java鐨刟dd鐘舵€?/pre>log锛氭煡鐪嬫彁浜よ褰曪紙鍐呭鍖呭惈鎻愪氦id,鎻愪氦浜猴紝鎻愪氦鏃ユ湡锛屾弿杩颁俊鎭級
git log // 鎵€鏈夎褰昰it log xxxxx(id) -1 // 鏌ョ湅褰撳墠id鐨勮褰曪紝-1琛ㄧず涓€琛岃褰昰it log xxxxx(id) -1 -p // 鏌ョ湅褰撳墠id鎻愪氦璁板綍鐨勪慨鏀?/pre>git 鍒嗘敮
鍒嗘敮锛氬彲浠ュ湪鐜版湁浠g爜涓婃媺鍑轰竴涓垎鏀紝浣垮緱浠g爜鍙互鍦ㄤ富骞蹭笌鍒嗘敮鍚屾椂寮€鍙戯紝骞朵笖浠g爜涔嬮棿浜掔浉涓嶄細褰卞搷銆傚父瑙佷娇鐢ㄧ幆澧冿紝灏辨槸姣忔鐗堟湰鍙戝竷锛?宸插彂甯冪殑鍙互鎷夊嚭涓€涓垎鏀紝鍓╀笅鐨勫姛鑳界户缁湪涓诲共寮€鍙戯紝濡傛灉鍙戝竷鐗堟湰鏈夐棶棰橈紝鍙敤淇敼鍒嗘敮锛屾渶缁堝皢浠g爜鍚堝苟鍒颁富骞层€?/p>
鍒嗘敮鍛戒护锛?/p>
git branch -a // 鏌ョ湅鎵€鏈夊垎鏀紝master涓诲共锛屽垎鏀墠鏈?鍙凤紝琛ㄧず褰撳墠澶勪簬閭d釜鍒嗘敮git branch release1.0 // 鍒涘缓release1.0鍒嗘敮锛実it checkout release1.0 // 鍒囨崲鍒皉elease1.0鍒嗘敮锛屼富瑕佷笌鏂囦欢淇敼鎾ら攢鐨勫尯鍒玤it checkout master // 1锛?nbsp;鍒囨崲鍒颁富骞瞘it merge release1.0 // 2锛?nbsp;灏唕elease1.0鐨勪慨鏀瑰悎骞跺埌master锛屽鏋滄湁鍐茬獊瑙e喅鍐茬獊git branch -D release1.0 // 鍒犻櫎release1.0鍒嗘敮杩滅▼鐗堟湰搴?/h2>
姣斿鏈夎繙绋嬬増鏈簱锛?a href="https://github.com/FreeSunny/RefreashTabView.git">https://github.com/FreeSunny/RefreashTabView.git
git clone https://github.com/FreeSunny/RefreashTabView.git // 涓嬭浇鍒版湰鍦?/pre>杩滅▼搴撳懡浠わ細
push锛氬皢浠g爜淇敼鍜屾彁浜ゅ悓姝ュ埌杩滅▼搴揫閲嶈]
git push origin master //origin 鎸囧畾杩滅▼鐗堟湰搴撶殑 Git 鍦板潃锛宮aster 鎸囧畾鍚屾鍒板摢涓€涓垎鏀笂
fetch锛氳繙绋嬪簱鐨勪慨鏀瑰悓姝ュ埌鏈湴, 涓嶄細灏嗕唬鐮佸悎骞跺埌浠讳綍鍒嗘敮锛屼細瀛樻斁鍒颁竴涓猳rigin/master鍒嗘敮涓?/p>
git fetch origin master // 娉ㄩ噴鍚屼笂diff锛氭煡鐪嬭繙绋嬪簱淇敼鍐呭
git diff origin/master // 娉ㄦ剰鏈変竴涓枩绾匡紝灏辨槸fetch鍚屾鍚庢斁缃殑浣嶇疆merge锛氬皢origin/master鍒嗘敮淇敼鐨勫唴瀹瑰悎骞跺埌涓诲垎鏀?/p>
git merge origin/master // 娉ㄦ剰鏂滅嚎pull锛歠etch + merge锛屾媺鍙栧苟涓斿悎骞禰閲嶈]
git pull origin master // 娌℃湁鏂滅嚎瀹炰緥鎿嶄綔 gitbub缃戝潃
鐭ユ槗琛岄毦锛宻ay easy than do锛?涓嬮潰灏辨潵涓€涓皬灏忕殑瀹炰緥锛屽繀椤昏鏈塯it璐﹀彿锛岃繖涓楠ゅ氨涓嶇敤say浜嗗惂锛?/p>
鍒涘缓杩滅▼搴?/h3>
a. 鐐瑰嚮+鍙蜂笅鐨凬ew repository 鍒涘缓涓€涓繙绋嬪簱锛屽懡鍚嶄负GitOperate, b. 鐗堟湰搴撶被鍨嬪彲浠ublic鎴栬€卲rivate锛岀▼搴忓憳閮芥湁寮€婧愮殑蹇冿紝閭e氨public銆? c. 杩樺彲浠ュ嬀閫塈nitialize this repository with a README锛? d. 鎺ヤ笅鏉ュ彲浠ラ€夋嫨娣诲姞.gitignore鏂囦欢锛?gitignore鏂囦欢鏈夊緢澶氱被鍨嬪彲浠ラ€夛紝 姣斿 Android锛孉ndroid椤圭洰涓嬬殑bin杩欎簺鏂囦欢涓€鑸兘涓嶉渶瑕佹彁浜ゃ€?nbsp; 閫夋嫨閬靛惊鐨勫崗璁€俥g锛欰pache License 2.0, 杩欎釜鍙互鑷繁鍘绘煡鏌ユ瘡绉嶇殑鎰忔€? e. 鐐瑰嚮create锛岃繙绋嬬増鏈簱灏卞垱寤哄畬鎴愪簡锛岃繙绋嬬増鏈簱鐨勫湴鍧€涓?nbsp; https://github.com/FreeSunny/GitOperate.git銆? 涔嬪悗璺宠浆鍒癛EADME.md,璇ユ枃浠朵富瑕佹槸瀵归」鐩殑鎻忚堪銆?/pre>杩滅▼搴撳厠闅嗗埌鏈湴
a. 鏈湴鍒涘缓涓€涓狦itOperate鏂囦欢澶? b. 杩滅▼搴撳湴鍧€涓篽ttps://github.com/FreeSunny/GitOperate.git锛? cd杩涘叆GitOperate锛岃緭鍏?nbsp;*git clone https://github.com/FreeSunny/GitOperate.git* c. 瀹屾垚鍚庡彲浠ュ湪GitOperater鏂囦欢涓嬬殑GitOperate鏂囦欢澶逛笅鐪嬪埌README.md鏂囦欢锛堜袱灞傛枃浠跺す浜嗭級 d. 灏嗙浜屼釜鐩綍涓嬬殑鎵€鏈夋枃浠跺叏閮ㄥ鍒跺埌涓婁竴灞傜洰褰曚腑锛岃繖鏍峰氨鍙湁绗竴灞傜洰褰曟坊鍔犲埌鐗堟湰鎺у埗涓€? 鎿嶄綔鍛戒护涓?cp -r GitOperate/ .)鎻愪氦浠g爜
git add .// 灏嗘彁浜ょ殑浠g爜娣诲姞杩涙潵锛岃繖閲屾寚README.mdgit commit -m 鈥渁dd readme鈥?nbsp;// 鏈湴鎻愪氦git push origin master // 鍚屾鍒拌繙绋嬪簱
缃戞槗浜?a style="color: rgb(68, 119, 208); text-decoration: none" href="https://www.163yun.com/free#fc?tag=M_tg_292_64">鍏嶈垂浣撻獙棣?/span>锛?鎴愭湰浣撻獙20+娆句簯浜у搧锛?/p>
鏇村缃戞槗鐮斿彂銆佷骇鍝併€佽繍钀ョ粡楠屽垎浜璁块棶缃戞槗浜戠ぞ鍖?/span>銆?/p>
鐩稿叧鏂囩珷锛?br>銆愭帹鑽愩€?nbsp;浠g爜娣锋穯闃叉APP琚弽缂栬瘧鎸囧崡
銆愭帹鑽愩€?nbsp;闈炲绉板姞瀵嗕笌璇佷功锛堜笂绡囷級
以上是关于git 浣跨敤閭d簺浜嬪効的主要内容,如果未能解决你的问题,请参考以下文章
娴呰皥 Mac 榛戣嫻鏋?Hackintosh 瀹夎浣跨敤