十 涓緢鏈夌敤鐨勯珮绾?Git 鍛戒护

10 涓緢鏈夌敤鐨勯珮绾?Git 鍛戒护
10 涓緢鏈夌敤鐨勯珮绾?Git 鍛戒护

1. 杈撳嚭鏈€鍚庝竴娆℃彁浜ょ殑鏀瑰彉
杩欎釜鍛戒护锛屾垜缁忓父浣跨敤瀹?鏉ュ彂閫佸叾浠栨病鏈変娇鐢╣it鐨勪汉鏉ユ鏌ユ垨鑰呴泦鎴愭墍淇敼鐨勩€傚畠浼氳緭鍑烘渶杩戞彁浜ょ殑淇敼鍐呭鍒颁竴涓獄ip鏂囦欢涓€?

1
git archive -o ../updated.zip HEAD $(git diff --name-only HEAD^)

2. 杈撳嚭涓や釜鎻愪氦闂寸殑鏀瑰彉
绫讳技鐨勶紝濡傛灉浣犻渶瑕佽緭鍑烘煇涓や釜鎻愪氦闂寸殑鏀瑰彉鏃讹紝浣犲彲浠ヤ娇鐢ㄨ繖涓€?

1
git archive -o ../latest.zip NEW_COMMIT_ID_HERE $(git diff --name-only OLD_COMMIT_ID_HERE NEW_COMMIT_ID_HERE)
3. 鍏嬮殕 鎸囧畾鐨勮繙绋嬪垎鏀?
濡傛灉浣犳复鏈涘彧鍏嬮殕杩滅▼浠撳簱鐨勪竴涓寚瀹氬垎鏀紝鑰屼笉鏄暣涓粨搴撳垎鏀紝杩欏浣犲府鍔╁緢澶с€?

1
git init
2
git remote add -t BRANCH_NAME_HERE -f origin REMOTE_REPO_URL_PATH_HERE
3
git checkout BRANCH_NAME_HERE
4. 搴旂敤 浠庝笉鐩稿叧鐨勬湰鍦颁粨搴撴潵鐨勮ˉ涓?
濡傛灉浣犻渶瑕佸叾瀹冧竴浜涗笉鐩稿叧鐨勬湰鍦颁粨搴撲綔涓轰綘鐜板湪浠撳簱鐨勮ˉ涓侊紝杩欓噷灏辨槸閫氬線閭i噷鐨勬嵎寰勩€?

1
git --git-dir=PATH_TO_OTHER_REPOSITORY_HERE/.git format-patch -k -1 --stdout COMMIT_HASH_ID_HERE| git am -3 -k
5. 妫€娴?浣犵殑鍒嗘敮鐨勬敼鍙樻槸鍚︿负鍏跺畠鍒嗘敮鐨勪竴閮ㄥ垎
cherry鍛戒护璁╂垜浠娴嬩綘鐨勫垎鏀殑鏀瑰彉鏄惁鍑虹幇鍦ㄥ叾瀹冧竴浜涘垎鏀腑銆傚畠閫氳繃+鎴栬€?绗﹀彿鏉ユ樉绀轰粠褰撳墠鍒嗘敮涓庢墍缁欑殑鍒嗘敮涔嬮棿鐨勬敼鍙橈細鏄惁鍚堝苟浜?merged)銆?+ 鎸囩ず娌℃湁鍑虹幇鍦ㄦ墍缁欏垎鏀腑锛屽弽涔嬶紝- 灏辫〃绀哄嚭鐜板湪浜嗘墍缁欑殑鍒嗘敮涓簡銆傝繖閲屽氨鏄浣曞幓妫€娴嬶細

1
git cherry -v OTHER_BRANCH_NAME_HERE
2
#渚嬪: 妫€娴媘aster鍒嗘敮
3
git cherry -v master
6.寮€濮嬩竴涓棤鍘嗗彶鐨勬柊鍒嗘敮
鏈夋椂锛屼綘闇€瑕佸紑濮嬩竴涓柊鍒嗘敮锛屼絾鏄張涓嶆兂鎶婂緢闀垮緢闀跨殑鍘嗗彶璁板綍甯﹁繘鏉ワ紝渚嬪锛屼綘鎯冲湪鍏紬鍖哄煙锛堝紑婧愶級鏀剧疆浣犵殑浠g爜锛屼絾鏄張涓嶆兂鍒汉鐭ラ亾瀹冪殑鍘嗗彶璁板綍銆?

1
git checkout --orphan NEW_BRANCH_NAME_HERE
7. 鏃犲垏鎹㈠垎鏀殑浠庡叾瀹冨垎鏀疌heckout鏂囦欢
涓嶆兂鍒囨崲鍒嗘敮锛屼絾鏄張鎯充粠鍏跺畠鍒嗘敮涓幏寰椾綘闇€瑕佺殑鏂囦欢锛?

1
git checkout BRANCH_NAME_HERE -- PATH_TO_FILE_IN_BRANCH_HERE
8.蹇界暐宸茶拷韪枃浠剁殑鍙樺姩
濡傛灉鎮ㄦ鍦ㄤ竴涓洟闃熶腑宸ヤ綔锛岃€屼笖澶у閮藉湪鍚屼竴鏉ranch涓婇潰宸ヤ綔锛岄偅涔堟偍寰堟湁鍙兘浼氱粡甯哥敤鍒癴etch鍜宮erge銆備絾鏄湁鏃跺€欒繖鏍蜂細閲嶇疆鎮ㄧ殑鐜閰嶇疆鏂囦欢锛屽姝ょ殑璇濓紝鎮ㄥ氨寰楀湪姣忔merge鍚庝慨鏀瑰畠銆備娇鐢ㄨ繖涓€鍛戒护锛屾偍灏辫兘瑕佹眰git蹇借鎸囧畾鏂囦欢鐨勫彉鍔ㄣ€傝繖鏍凤紝涓嬪洖浣犲啀merge鐨勮瘽锛岃繖涓枃浠跺氨涓嶄細琚慨鏀逛簡銆?

1
git update-index --assume-unchanged PATH_TO_FILE_HERE
9.妫€鏌ユ彁浜ょ殑鍙樺姩鏄惁鏄痳elease鐨勪竴閮ㄥ垎
name-rev鍛戒护鑳藉憡璇夋偍涓€涓猚ommit鐩稿浜庢渶杩戜竴娆elease鐨勪綅缃€備娇鐢ㄨ繖鏉″懡浠わ紝鎮ㄥ氨鍙互妫€鏌ユ偍鎵€鍋氬嚭鐨勬敼鍔ㄦ槸鍚︽槸release鐨勪竴閮ㄥ垎浜嗐€?

1
git name-rev --name-only COMMIT_HASH_HERE
10.浣跨敤rebase鎺ㄩ€佽€岄潪merge
濡傛灉鎮ㄦ鍦ㄥ洟闃熶腑宸ヤ綔骞朵笖鏁翠釜鍥㈤槦閮藉湪鍚屼竴鏉ranch涓婇潰宸ヤ綔锛岄偅涔堟偍灏卞緱缁忓父鍦拌繘琛宖etch/merge鎴栬€卲ull銆侴it涓紝鍒嗘敮鐨勫悎骞朵互鎵€鎻愪氦鐨刴erge鏉ヨ褰曪紝浠ユ琛ㄦ槑涓€鏉eature鍒嗘敮浣曟椂涓庝富鍒嗘敮鍚堝苟銆備絾鏄湪澶氬洟闃熸垚鍛樺叡鍚屽伐浣滀簬涓€鏉ranch鐨勬儏褰腑锛屽父瑙勭殑merge浼氬鑷磍og涓嚭鐜板鏉℃秷鎭紝浠庤€屼骇鐢熸贩娣嗐€傚洜姝わ紝鎮ㄥ彲浠ュ湪pull鐨勬椂鍊欎娇鐢╮ebase锛屼互姝ゆ潵鍑忓皯鏃犵敤鐨刴erge娑堟伅锛屼粠鑰屼繚鎸佸巻鍙茶褰曠殑娓呮櫚銆?

1
git pull --rebase
鎮ㄤ篃鍙互灏嗘煇鏉ranch閰嶇疆涓烘€绘槸浣跨敤rebase鎺ㄩ€侊細

1
git config branch.BRANCH_NAME_HERE.rebase true
鏈枃鍦板潃锛歨ttps://www.oschina.net/translate/10-useful-advanced-git-commands

相关内容推荐