Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Git Advanced Tutorial     - CentOS boot image to achieve semi-automatic installation (Linux)

- Install Python 3.3.4 under CentOS 6.4 (Linux)

- Oracle 11g tracking and monitoring system-level triggers to drop misuse (Database)

- How to use SHA256 checksum files download (Linux)

- Android Application Development: Genymotion can not start solving (Linux)

- Arduino UNO simulation development environment set up and run simulation (Linux)

- BGP routers want to play it by CentOS (Linux)

- Using monitoring tool dsniff (Linux)

- Spring AOP for logging (Programming)

- When should I use Angular 2 (Programming)

- linux smartd [FAILED] appears at startup (Linux)

- pkg-config to use (Linux)

- DDOS Attacks and Prevention (Linux)

- Linux iptables: combat scenes (Linux)

- CentOS7 set boot directly into the command line interface (Linux)

- RedHat 6 xrdp use remote login interface (Linux)

- Linux remote connectivity tools -OpenSSH (Linux)

- Advanced permissions Linux file system settings (Linux)

- Ubuntu15 core CLR (Server)

- Monitoring services are running properly and will email alert (Server)

  Git Advanced Tutorial
  Add Date : 2016-07-11      
  Today is said to be accidentally saw Git introductory tutorial, read later learned many new things, learn things themselves summarize and record, always feel less of something else.

Explanatory work area (working directory), the repository (Repository), temporary storage area (stage), and the concept of the following branches.

The following explanation is not entirely precise, please combined figure to understand the following four concepts.
Workspace (working dicrectory): The parent directory contains .git directory is the general work area is our project directory. Newly created files are in the work area at this time is not a member to be explained later suspended the area.

Repository (Repository) :. git directory is the repository, version management of all relevant documents in this directory.

Suspend area (stage): For the latter had joined the version control file has been modified to perform file git add would be put on hold after area.

Branch: git initial default creates a master branch, after executing git commit, the file would defer to the district branch inside.

There follows a readme.rst file is already added to the repository, and now after the content changes, the state view

E: \ Users \ aaa \ workspace \ blog> git status

# On branch master
# Your branch is ahead of 'origin / master' by 4 commits.
# (Use "git push" to publish your local commits)
# Changes not staged for commit:
# (Use "git add < file> ..." to update what will be committed)
# (Use "git checkout - < file> ..." to discard changes in working d
# Modified: README.rst
no changes added to commit (use "git add" and / or "git commit -a")
git prompt README.rst has been modified, but not the file on hold area (not staged), pending commit. Then you can also tell how the operation, checkout means the withdrawal of this revision, watch behind - if you do not take this character, checkout is another layer of meaning.

Return to the specified version

Return to the specified version using the command git reset --hard < version>, HEAD always points to the current version, HEAD ^^ represents the previous version. If you would like to return to a previous version, you can use:

git reset --hard HEAD ^^
If you would like to return to a specific version of it? You can use git log commit See obtain the version number:

commit 33b351ae746edaf3fd5a56a0318235096b6ed1ce
Author: aaa
Date: Sat Mar 15 11:43:56 2014 +0800
    commit many files

commit 86eefaaea5251fa5707ecd02009c893c098ab6cd
Author: aaa
Date: Thu Mar 14 03:20:27 2013 +0800

    add author myself
commit is behind the string of the version number, as long as the general in front of several select it. git automatically to find.

git reset --hard 86eefa
Implementation of the above command is returned to the specified version, if I go back now, and want to restore to the most recent version of how to do that? As long as you remember this latest version, then direct execution of the above commands like, but who have to remember this number ah? So there is a way to use git reflog view, this command records each operation.

E: \ Users \ aaa \ workspace \ blog> git reflog
a11c917 HEAD @ {0}: reset: moving to a11c
        HEAD @ {1}: reset: moving to HEAD ^
        HEAD @ {2}: reset: moving to a11c917430050a94549e48d205ef01cacc82c1cf
        HEAD @ {3}: reset: moving to HEAD ^
The above allc ... what I most recently revised.

Modify (change)

This change is not a verb, but a noun, as long as the document is changed to indicate changes, including changes to the contents of a file or a newly created file or delete a file called a modification. git track (track) is modified, rather than the file itself.

Undo (checkout)

Revocation refers to the modified file, has not added to the suspended area (not yet executed git add) process modifications revocation out, if you have added to the hold area, but has not yet commit to a branch to go, and made a revised want revocation, this revocation is to cancel the state to suspend the zone. For example, the file will now add content to "add some to file":

E: \ Users \ aaa \ workspace \ blog> git status
# On branch master
# Your branch is ahead of 'origin / master' by 4 commits.
# (Use "git push" to publish your local commits)
# Changes not staged for commit:
# (Use "git add ..." to update what will be committed)
# (Use "git checkout - ..." to discard changes in working directory)
# Modified: README.rst
Then add it to suspend District:

git add README.rst
Add content "add some again to file", after the withdrawal, you will find the first additions to retain the second additions withdrawn.

E: \ Users \ aaa \ workspace \ blog> git checkout - README.rst

E: \ Users \ aaa \ workspace \ blog> git status
# On branch master
# Your branch is ahead of 'origin / master' by 4 commits.
# (Use "git push" to publish your local commits)
# Changes to be committed:
# (Use "git reset HEAD ..." to unstage)
# Modified: README.rst
Branch Management

When developing a new feature, it may take several weeks to complete, you can create a branch, do development on a branch, without affecting the function of the main branch.

Create a branch:

git branch dev
git checkout dev
Or combined into a single command:

git checkout -b dev
After you create a dev branch switching, HEAD pointer from the original master transfer point to dev branch, git branch you can see what branch, and is currently on which branch.

E: \ Users \ aaa \ workspace \ blog> git branch
* Dev
The asterisk represents the current branch is located.

Switching branches:
git checkout master

Merge branch:
After switching branch, the dev branch changes in the master branch can not see, if the dev branch function developed, we can consider merging branches, the merger can also delete dev branch, because the dev branch for us It has little meaning.

git merge dev
The combined master branch is to execute dev branch, then you can also remove branches

git branch -d dev
git branch encouraged everyone to use, so we remember to use ah, is the only multi-master.


If different people to the same place the same file has been modified, it will encounter conflict submitted, or on a different branch changes to the same place the same file will be a conflict, when there is conflict, you must manually place the conflict be revised and resubmitted in order to resolve the conflict.

Create a branch dev, then add content "add new branch dev", after the switch to the master branch commit, add content to the same line "may be here is conflict", after the merge commit.

git checkout -b dev
git add README.rst
git commit -m "add new branch"
git checkout master
git add README.rst
git commit -m "add new line"
git merge dev

#An error occurred
Auto-merging README.rst
CONFLICT (content): Merge conflict in README.rst
Automatic merge failed; fix conflicts and then commit the result.
README.rst content appeared the following:

<<<<<<< HEAD
may be here is conflict
add new branch dev
>>>>>>> Dev
<<<<<<< To ======= \ represents the current contents of the branch, showing dev >>>>> contents inside. Manually modify the contents inside before submitting. Then the master is the latest files. Of course, dev or remain in the state last commit. At this point you might be thinking, I think the dev branch to maintain the same date with the master, then you can do:

git checkout dev
git rebase master
Fast equivalent to dev branch point to master.

Branching strategy

The development process should be in the following ways to manage the branch.
Main branch: Code library should have one and only one main branch master, master branch code is stable only for official release to use.

Development branch: daily development work should be in the development branch dev completed until sometime dev branch function complete the merge can be considered up to the master branch.

Own branch: each person build their own branch in the dev branch.
By default, git merge use the "fast forward" mode, which is equivalent to point directly to the master branch dev branch. After you remove the branch, the branch information is immediately lost.

In the time of the merger attach parameters --no-ff can disable fast-forward merge mode. So the master can generate a new node, the branch information retention means master, and this way we hope to adopt the merger.

git merge --no-ff dev
- Use SVN to automatically deploy code under Apache (Server)
- To execute the cp command prompt type skip folder under CentOS (Linux)
- Infinispan 8 new Redis cache storage implementation (Linux)
- Use pg_basebackup build PostgreSQL streaming replication environment (Database)
- Build RPM package uses Docker mirror (Linux)
- Depth understanding of JavaScript new mechanism (Programming)
- MongoDB study notes - polymerization (Database)
- Binary search -Java achieve (Programming)
- Text analysis tools - awk (Linux)
- Talk about Java in the collection (Programming)
- Linux system security configuration (Linux)
- Oracle metadata Reconstruction experiments (Database)
- Spring declarative transaction management (Programming)
- Linux, Eclipse flash back and reinstall the JDK methods (Linux)
- Management DB2 logs (Database)
- How to understand Python yield keyword (Programming)
- Linux user management (Linux)
- Using DBMS_STAT function closes mission (Database)
- Linux log management tools Logrotate (Linux)
- DVD production using CentOS installation source within the company Yum (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.