Git Using Command

create a remote git-server-repository

ref: http://toyroom.bruceli.net/tw/2011/02/04/install-git-server-on-ubuntu-linux.html

ref: http://blogger.gtwang.org/2014/02/linux-git-server-using-ssh.html

  1. prepare folder location of git server
cd /opt/
sudo mkdir gitserver
cd gitserver
  1. create project for git server and init git server environment
    sudo mkdir my_project.git
    cd my_project.git
    sudo git init --bare --shared
    

sucessful message: Initialized empty shared Git repository in /opt/gitserver/my_project.git/

create a user account for git group.

todo ..

clone a git project in git client

sudo git clone ssh://[email protected]:/opt/gitserver/my_project.git

local files(non-connect git) push to remote git server

git init
git commit -m "init"
git add .
sudo git push -u origin master

copy an exist git repository to local files

Combining multiple commits before pushing in Git

git rebase -i origin/master

ref web-site, ref web-site 2

Recovey(undo) git command

git reset

add modify/remove files only. (ignore untrackes files)

git add -u

remove files when you add some incorrect files

git rm --cache 'filename'

Change Branch

ref: http://stackoverflow.com/questions/1783405/checkout-remote-git-branch I have a branch called test, how can I change master branch to test branch?

git fetch
git checkout test

顯示特定commit的修正紀錄

git show $commit

ex: git show 86a089a887994d753ad8909f5195038e8ca2a993

追蹤特定檔案在當前的branch的commit紀錄

git log --follow $filePath

ex: git log --follow EngineerSetup/java/com/inspur/mod/engineeringpage/utils/RetrieveConfiguration.java

重新整理遠端不必要的commit

假設現在遠端有 A->B->C->D->E->F->G | HEAD 目前遠端是在G, 但因為D,E,F,G這幾個都被改壞了, 不再被需要, 因此遠端要回推到C, 那要怎麼處理呢?

git reset --hard $C-COMMIT-ID
git push -f origin &BranchName

results matching ""

    No results matching ""