Git
Git Topics
- Install Git
- Git daemon
- Initialize Git config
- Command
- Basic Use
- Share repository
- Configuration
Install Git
Cent OS
sudo yum install git
Ubuntu
sudo apt-get install git
Linux are both GUI and CUI.
In the past, git-core is actual package for git, but now git is.
Windows msysGit
Git daemon
Ubuntu
sudo apt-get install git-daemon-run
Initialize Git config
Initialize git repository without any settings
Create target directory with mkdir
Move to the directory you created.
Type
git init
Initialize repository
.git directory(setting files) is created under the directory.
Set default user name and email address
git config --global user.name "Kiririn" git config --global user.email kiririn@kiririn.com
If missing this settings, you cannot commit.
.git directory under the current.
Init bare repository
This is empty repository(management file), there are only setting files in
For server?
git init --bare --shared=true
Command
Command | Description |
---|---|
init | Initialize repository |
config | Show and change setting |
add | Add file to staging area |
rm | Remove file |
mv | Move file |
commit | Commit to the repository |
branch | Create branch and show status |
checkout | Change branch |
merge | Merge differences |
pull | Merge changes from remote repository |
fetch | Get changes from the remote repository |
push | Update changes to remote repository |
remote | Show remote repository settings |
status | Show status |
log | Show logs |
diff | Show differences |
git command arguments
Basic Use
- Create new file and make index
- Commit
- Commit and open editor for commit message
- Commit under .
- Edit the latest commit message
- Remove file
- Show current change(latest change)
- Show git log
- Show first 7 lines with simple message
- Compare two commits
- Revert
- Revert all(Hard reset)
- Reset(Unstage) from index
Create new file and make index
Inform my status to Git(make index)
git add sample.txt
sample.txt is file name
Apply all files under directory
git add .
Commit
git commit -m "first check-in"
“” is commit message(check-in message)
Steps are add and commit.
Commit and open editor for commit message
git commit
Open editor to input commit message
Commit under .
This command isn’t required to add
git commit -a -m "Comment"
Edit the latest commit message
You’ve already commited.
After commit, you want to edit commit message.
git commit --amend
Open editor and you can edit message
Remove file
git rm filename
This applies to index. You need to commit after it.
Show current change(latest change)
git show
–amend: Edit HEAD(latest)
Show git log
git log
Log example
commit 1ce2003e83f9eff0456e3a47025197359f27c2ed Author: kiririnDate: Sun Sep 15 12:30:13 2013 +0900 first check-in
Show first 7 lines with simple message
git log --oneline
This command to show HEAD, master log
Compare two commits
git diff 6cac3f4 1ce2003 sample.txt
Use one line simple commit ID with –oneline sample.txt is file name
Revert
Use git checkout
git checkout HEAD filename
Restore specific version
git checkout 6cac34f filename
Revert all(Hard reset)
git reset --hard HEAD
If you want to 1 back stage from HEAD
git reset --hard HEAD~
~ is 1 backward
Reset(Unstage) from index
Clear index(clear added files)
git reset HEAD filename
Show current status in index
git status
Show command Help
git commandname -h
Rename
git mv file1 file2
Include all changes(add, change, remove)
Include all changes in index
git add -A git commit -m ""
Remove from only index
File is still existed under working tree
git rm --cached filename
Ignore file from(git add, git add -A)
Remove specific targets from index. Sometimes we don’t need to check-in files(tmp, binary, or others).
In that case, we can use ignore files.
To register ignore files
- project/.gitignore
- project/.git/info/exclude
- git config –global core.excludesfile $HOME/.gitexclude
Create an ignore file
.gitignore
# comment *.thumb bin/ obj/
Share repository
Copy existed git repository
git clone /User/kiririn/Public/project help_project
The arguments order is oritinal, dst
In this case, we use share directory(not ssl)
Copy remote repository with ssh
git clone ssh://kiririn.com/~kiririn/Public/project.git
The style ssh://username@hostname:port/repotitorypath
To use git protocol, use git://
Get other people’s change
git pull /User/Ayase/Public/help_project
The argument is target
Show(check) latest commit
git show
Merge commit
Merge is a point of version management system.
In git, when git pull is performed, editor opens
Editor shows merge(conflicts)
Git merge automatically
Add remote setting
Check remote repository
Full description
Add remote
Configuration
- Show configuration list
- Show git version
- Add username, user email
- Remove parameter from config
- Change default git editor
- Color enabled
- Enable decorate option by default
Show configuration list
git config --list
Add username, user email
git config --global user.name "Kiririn" git config --global user.email kiririn@kiririn.com
Show git version
git version
Remove parameter from config
git config --global --remove-section property
Change default git editor
To edit commit message, git uses “vi” by default.
To change this, you need to change core.editor
git config --global core.editor emacs
This case is emacs, other you also can change nano
Color enabled
git config --global color.ui auto
Enable decorate option by default
git config --global log.decorate short