Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Git Advanced Tutorial     - Servlet life cycle code examples (Programming)

- IP configuration under Linux (Linux)

- Docker use Dockerfile created since the launch of the service support SSH container mirror (Server)

- Linux Network Programming - raw socket programming (Programming)

- Error: Unable to establish connection with FTP SFTP server (Server)

- Vim Common Command Summary (Linux)

- After VMware CentOS full VM clone the network card is unavailable Solutions (Linux)

- Struts2 configure a static resource files without Struts processing (regular match) (Programming)

- How to install Laravel PHP framework on CentOS 7 / Ubuntu 15.04 (Server)

- Linux file and directory management - ls, cp, mv (Linux)

- About Linux operating system security (Linux)

- Bash difference in single quotes and double quotes (Programming)

- Getting the Linux shell flow control statements (Programming)

- PHP parsing algorithm of the interview questions (Programming)

- Use Ansible to bulk manage remote servers (Server)

- VMware virtual machine can not start VMnet0 no Internet access and other issues (Linux)

- phpinfo (): like phpinfo as a Python script (Programming)

- Using Python multithreaded mistakes summary (Programming)

- Linux server startup and logon security settings (Linux)

- Ubuntu way of decompressing files (Linux)

  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
- Shuffle Process Arrangement in MapReduce (Server)
- Build Eclipse + Maven + Scala-IDEA the Scala Web development environment (Server)
- jQuery plugin dynamic label generation (Linux)
- How to disable IPv6 on Ubuntu, Linux Mint, Debian (Linux)
- Fedora 22 installation and configuration optimization (Linux)
- Linux rights management (Linux)
- File SUID, SGID, Sticky property (Linux)
- Those things packaged using Gradle to Android (Programming)
- RPM package creation Getting Started (Linux)
- Ten minutes to find out the character set and character encoding (Linux)
- Oracle11g Trigger Debugging Record Error: PLS-00201: identifier SYS.DBMS_SYSTEM 'must be declared (Database)
- Guide: Trickle restrict application bandwidth usage (Linux)
- Ubuntu dual-card system configuration method (Server)
- Windows and Ubuntu dual system, repair of two ways UEFI boot (Linux)
- ORA-12537: TNS: connection closed error process (Database)
- Redmine Installation (Linux)
- How to use Linux to download music from Grooveshark (Linux)
- When Vim create Python scripts, vim autocomplete interpreter and encoding method (Programming)
- Linux environment installation of rvm and ruby (Linux)
- MySQL and MariaDB new master from the cluster configuration GTID (Database)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.