git
来源:互联网 发布:知乎 福利 文 编辑:程序博客网 时间:2024/06/15 00:25
原文链接
create a new repository
create a new directory, open it and perform a git init
to create a new git repository.
checkout a repository
create a working copy of a local repository by running the commandgit clone /path/to/repository
when using a remote server, your command will begit clone username@host:/path/to/repository
workflow
your local repository consists of three "trees" maintained by git. the first one is yourWorking Directory
which holds the actual files. the second one is theIndex
which acts as a staging area and finally the HEAD
which points to the last commit you've made.
add & commit
You can propose changes (add it to the Index) usinggit add <filename>
git add *
This is the first step in the basic git workflow. To actually commit these changes usegit commit -m "Commit message"
Now the file is committed to the HEAD, but not in your remote repository yet.
pushing changes
Your changes are now in the HEAD of your local working copy. To send those changes to your remote repository, executegit push origin master
Change master to whatever branch you want to push your changes to.
If you have not cloned an existing repository and want to connect your repository to a remote server, you need to add it withgit remote add origin <server>
Now you are able to push your changes to the selected remote server
branching
Branches are used to develop features isolated from each other. The master branch is the "default" branch when you create a repository. Use other branches for development and merge them back to the master branch upon completion.
create a new branch named "feature_x" and switch to it usinggit checkout -b feature_x
switch back to mastergit checkout master
and delete the branch againgit branch -d feature_x
a branch is not available to others unless you push the branch to your remote repositorygit push origin <branch>
update & merge
to update your local repository to the newest commit, execute git pull
in your working directory to fetch and merge remote changes.
to merge another branch into your active branch (e.g. master), usegit merge <branch>
in both cases git tries to auto-merge changes. Unfortunately, this is not always possible and results inconflicts. You are responsible to merge those conflicts manually by editing the files shown by git. After changing, you need to mark them as merged withgit add <filename>
before merging changes, you can also preview them by usinggit diff <source_branch> <target_branch>
tagging
it's recommended to create tags for software releases. this is a known concept, which also exists in SVN. You can create a new tag named1.0.0 by executinggit tag 1.0.0 1b2e1d63ff
the 1b2e1d63ff stands for the first 10 characters of the commit id you want to reference with your tag. You can get the commit id by looking at the...
log
in its simplest form, you can study repository history using.. git log
You can add a lot of parameters to make the log look like what you want. To see only the commits of a certain author:git log --author=bob
To see a very compressed log where each commit is one line:git log --pretty=oneline
Or maybe you want to see an ASCII art tree of all the branches, decorated with the names of tags and branches:git log --graph --oneline --decorate --all
See only which files have changed: git log --name-status
These are just a few of the possible parameters you can use. For more, see git log --help
replace local changes
In case you did something wrong, which for sure never happens ;), you can replace local changes using the commandgit checkout -- <filename>
this replaces the changes in your working tree with the last content in HEAD. Changes already added to the index, as well as new files, will be kept.
If you instead want to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it like thisgit fetch origin
git reset --hard origin/master
useful hints
built-in git GUIgitk
use colorful git outputgit config color.ui true
show log on just one line per commitgit config format.pretty oneline
use interactive addinggit add -i
links & resources
graphical clients
- GitX (L) (OSX, open source)
- Tower (OSX)
- Source Tree (OSX & Windows, free)
- GitHub for Mac (OSX, free)
- GitBox (OSX, App Store)
guides
- Git Community Book
- Pro Git
- Think like a git
- GitHub Help
- A Visual Git Guide
get help
- Git User Mailing List
- #git on irc.freenode.net
- git
- git
- Git
- Git
- Git
- Git
- git
- git
- Git
- GIT
- git
- GIT
- Git
- git
- git
- Git
- GIt
- git
- Myeclipse项目JDK编译版本与环境版本不一致
- 逻辑回归原理
- 欢迎使用CSDN-markdown编辑器
- 搭建一个redis高可用系统
- Tensorflow 基本使用
- git
- Stored Procedure存储过程基础知识详解
- spring boot mybatis结合初探
- 动态添加 data 属性的时候 发现某一个值无法取到
- 第14章:日志管理
- 结构体数组,结构体指针 (C,随笔)
- 排序算法总结(4)--希尔排序
- 【LeetCode】路径系列
- Android定制:修改开机启动画面
comments