Git 应用

来源:互联网 发布:花都 知乎 编辑:程序博客网 时间:2024/06/10 03:54

1. initialize new repository

   1)   mkdir e:/prj/repo   //make directory where u want your repository in

   2)  cd e:/prj/repo

   3)  git init

   4)   //copy your codes directory to the directory your made just before 

   5)   add “.gitignore" file  //Ignoresomefiles, folders, need not submit

        //************************************************************************//

        //**************example for one .gitignore file *************************//

*.idb
*.obj
*.sbr
*.bsc
*.ilk
*.pdb
*.ncb
*.plg
*.pch
*.bak
.svn
.svn-base
  

    //*********************************.gitignore file end*****************************************//

    6) //add your code directroy to local repository

        git add MyDir

   7) commit change to local repository

       git commit -m "

   8) review the log

        git log

    //Information like the following will be shown

 

//******************************Informaion start *****************************************//

$ git log
commit 0a42a7179f1fe830f9d226856698b1dc97c150ff
Author: user <
wangyilong163@163.com>
Date:   Thu Jul 26 18:24:19 2012 +0800

    Initlize repository for control OrderMake source

user@ASUS-E504D7A0F1 /e/prj/repo (master)
$

 //******************************Information end**************************************//

 9) Now the initialize procedure is complete.You can control your code in local.

     If u want your codes can administ by other PC ,please refer to <<add local repository to server>>.

2. Update your changes to local repository

      git commit -a -m "Change ... for ..."

3. Update your change to server repository

     1)  git commit -a -m "Changed ... for ..."

     2)  git push --repo url

           Example : git push --repo /home/repo/order.git

                            git push --repouser@192.13.1.146:/home/repo/order.git

4. get one repository from the Git server

     git clone [url]

     Example :  git clone /home/repo/order.git

                         git clone user@192.12.1.146:/home/user/order.git

 

      Descriptor:

  • <user>   which is user name in server (192.12.1.146)
  • /home/user/order.git  is absolute path in server side。If use relative path ,write like this "git cloneuser@192.12.1.146:order.git

 

5. add file(s)

      git add "file" //Note: After this command ,only "add" command is recorded to repository,the file is not added to repository yet.  

6. delete file(s)

7.  create branch

       git checkout -b vga-version master //create "vga-version" branch form "master" branch

8.  merge branch

       1)  git checkout master

        2) git merge "branch"  //"branch" is the branch which will be merged to "master " branch 

9. tag

10. get the history version or history file

        1) git log  //show all versions to find out which version is you need

        2) git checkout "ID of commition"

       3) git checkout "file"  //get file commited at last time

11. abandon your change from lastest commition

          git  reset --hard

 

12. Compare difference version in repository

          1)  git diff   //compare difference between current edit and latest version commited to repository

          2)  git diff ffd98b291e0caa6c33575c1ef465eae661ce40c9 b8e7b00c02b95b320f14b625663fdecf2d63e74c

               //compare two versions have been saved in repository

13. add local repository to server

    a) in the PC you local repository saved in,

          1)  git clone --bare . "DestDir"   

               //"DestDir" means the direcroy u want your repository save to.

          2)  ssh-keygen -t rsa  //generate your key and save it to file

          3)  //transmit your "KeyCode.pub" and "DestDir" to administrator

   b) in server side

        1) copy your bare repository to "/home/repo/

             copy your keycode.pub to keydir of gitosis-admin repository

        2) change owner of this repository

              chown -R "Admin" "RepoDir"

        3) modify  ".gitosis.conf" file

           Example :

          [group OrderMake]

          members = user@Coall-workStation1 root

         writable = OrderMake

 

     

原创粉丝点击