git 知识整理

来源:互联网 发布:it男是接盘侠 编辑:程序博客网 时间:2024/05/19 12:27

官网: http://git-scm.com/book

我的github: https://github.com/huntinux

有用的代码可以提交上去

其它教程:    强烈推荐的教程

http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000


我总结的git用法:https://github.com/huntinux/gitpractise



==========搭建git server============

gitosis 但见方便,就是界面比较简陋。先拿来爽一下,以后有时间在搭建漂亮的gitlab

参考: http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way/

             http://www.jiangmiao.org/blog/1600.html

             http://wiki.ubuntu.org.cn/Git%E6%9C%8D%E5%8A%A1%E5%99%A8Gitosis%E5%AE%89%E8%A3%85%E8%AE%BE%E7%BD%AE   最后有说怎么搭建web界面。


==============使用github搭建博客=========

我的github博客地址: http://huntinux.github.io/
https://help.github.com/articles/creating-pages-with-the-automatic-generator      

http://www.ruanyifeng.com/blog/2012/08/blogging_with_jekyll.html
http://www.heiniuhaha.com/lessons/2012/08/09/use-jekyll-build-blog/


================使用总结===================

1、删除commit

    git reset --hard <commit_id>    git push origin HEAD --force

2、undo change to a file

=============== markdown ==================

语法

在线编辑器



=================搭建git server=======================

首先安装 ssh-server

$ sudo apt-get install openssh-server

www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137583770360579bc4b458f044ce7afed3df579123eca000

https://www.howtoforge.com/how-to-run-your-own-git-server-with-gitlabhq-on-ubuntu-14.04

www.darrenfang.com/2014/08/install-git-on-ubuntu/


初始化项目的脚本:

## create new project#if [ $# != 1 ];thenecho "Usage: $0 project_name"exit 1;fiproject_name=$1echo "project name: $project_name"cd /srv/gitsudo git init --bare $project_name".git"sudo chown -R git:git $project_name".git"echo "done."serveraddr=`ifconfig wlan0 | grep "inet addr" | cut -d: -f2 | cut -d' ' -f1`echo "you can clone it throug run:"echo "git clone git@$serveraddr:/srv/git/${project_name}.git"


备份代码叫脚本:

#!/bin/bash## back up code in git#function backup() {#CODE_GIT="git@localhost:/srv/git/servercode_mb.git"#BACKUP_DIR=`date +%Y-%m-%d-%H-%M-%S`CODE_GIT=$1BACKUP_DIR=$2PACKAGE_NAME=${CODE_GIT##*/}PACKAGE_NAME=${PACKAGE_NAME%.git}TAR_FILE=${PACKAGE_NAME}.tar.gzmkdir $BACKUP_DIRif [ ! -d $BACKUP_DIR ]; then echo "Failed to create directory [$BACKUP_DIR]"  exit 1elseecho "Create backup directory : $BACKUP_DIR"fiecho "Enter [$BACKUP_DIR]"cd $BACKUP_DIRecho "clone code into [$BACKUP_DIR]"git clone $CODE_GITecho "compress it into tar file: $TAR_FILE"tar czf $TAR_FILE $PACKAGE_NAMErm -rf $PACKAGE_NAMEecho donecd -}backupdir=`date +%Y-%m-%d-%H-%M-%S`if [ ! -d $backupdir ]; thenmkdir $backupdirfibackup "git@localhost:/srv/git/servercode_mb.git" $backupdirb



========================


  •  修改推送地址

         git remote add newurl  git@server:/srv/git/some.git

         git push newurl maste

0 0
原创粉丝点击