当前位置: 首页 > 编程日记 > 正文

Git 详解

1. Git

Git是用C语言开发的分布版本控制系统。版本控制系统可以保留一个文件集合的历史记录,并能回滚文件集合到另一个状态(历史记录状态)。另一个状 态可以是不同的文件,也可以是不同的文件内容。举个例子,你可以将文件集合转换到两天之前的状态,或者你可以在生产代码和实验性质的代码之间进行切换。文 件集合往往被称作是“源代码”。在一个分布版本控制系统中,每个人都有一份完整的源代码(包括源代码所有的历史记录信息),而且可以对这个本地的数据进行 操作。分布版本控制系统不需要一个集中式的代码仓库。

当你对本地的源代码进行了修改,你可以标注他们跟下一个版本相关(将他们加到index中),然后提交到仓库中来(commit)。Git保存了所 有的版本信息,所以你可以转换你的源代码到任何的历史版本。你可以对本地的仓库进行代码的提交,然后与其他的仓库进行同步。你可以使用Git来进行仓库的 克隆(clone)操作,完整的复制一个已有的仓库。仓库的所有者可以通过push操作(推送变更到别处的仓库)或者Pull操作(从别处的仓库拉取变 更)来同步变更。

Git支持分支功能(branch)。如果你想开发一个新的产品功能,你可以建立一个分支,对这个分支的进行修改,而不至于会影响到主支上的代码。

Git提供了命令行工具;这个教程会使用命令行。你也可以找到图形工具,譬如与Eclipse配套的EGit工具,但是这些都不会在这个教程中进行描述。

表 1. Git 术语

术语定义

仓库(Repository)

一个仓库包括了所有的版本信息、所有的分支和标记信息。在Git中仓库的每份拷贝都是完整的。仓库让你可以从中取得你的工作副本。
分支(Branches)一个分支意味着一个独立的、拥有自己历史信息的代码线(code line)。你可以从已有的代码中生成一个新的分支,这个分支与剩余的分支完全独立。默认的分支往往是叫master。用户可以选择一个分支,选择一个分支叫做checkout.

标记(Tags)

一个标记指的是某个分支某个特定时间点的状态。通过标记,可以很方便的切换到标记时的状态,例如2009年1月25号在testing分支上的代码状态

提交(Commit)

提交代码后,仓库会创建一个新的版本。这个版本可以在后续被重新获得。每次提交都包括作者和提交者,作者和提交者可以是不同的人
URLURl用来标识一个仓库的位置

修订(Revision)

用来表示代码的一个版本状态。Git通过用SHA1 hash算法表示的id来标识不同的版本。每一个 SHA1 id都是160位长,16进制标识的字符串.。最新的版本可以通过HEAD来获取。之前的版本可以通过"HEAD~1"来获取,以此类推。

Git 需要将代码的变化显示的与下一次提交进行关联。举个例子,如果你对一个文件继续了修改,然后想将这些修改提交到下一次提交中,你必须将这个文件提交到索引中,通过git add file命令。这样索引可以保存所有变化的快照。

新增的文件总是要显示的添加到索引中来。对于那些之前已经提交过的文件,可以在commit命令中使用-a 选项达到提交到索引的目的。

在Ubuntu上,你可以通过apt来安装git命令行工具

sudo apt-get install git-core

对于其他的Linux版本,请查看相关的软件包安装工具使用方法

msysgit项目提供了Windows版本的Git,地址是http://code.google.com/p/msysgit/

你可以在.gitconfig文件中防止git的全局配置。文件位于用户的home目录。 上述已经提到每次提交都会保存作者和提交者的信息,这些信息都可以保存在全局配置中。

后续将会介绍配置用户信息、高亮显示和忽略特定的文件

通过如下命令来配置用户名和Email

# Configure the user which will be used by git
# Of course you should use your name
git config --global user.name "Example Surname" # Same for the email address git config --global user.email "your.email@gmail.com" # Set default so that all changes are always pushed to the repository git config --global push.default "matching"

获取Git配置信息,执行以下命令:

git config --list

以下命令会为终端配置高亮

git config --global color.status auto
git config --global color.branch auto

可以配置Git忽略特定的文件或者是文件夹。这些配置都放在.gitignore文件中。这个文件可以存在于不同的文件夹中,可以包含不同的文件匹配模式。为了让Git忽略bin文件夹,在主目录下放置.gitignore文件,其中内容为bin。

同时Git也提供了全局的配置,core.excludesfile

Git会忽略空的文件夹。如果你想版本控制包括空文件夹,根据惯例会在空文件夹下放置.gitkeep文件。其实对文件名没有特定的要求。一旦一个空文件夹下有文件后,这个文件夹就会在版本控制范围内。

后续将通过一个典型的Git工作流来学习。在这个过程中,你会创建一些文件、创建一个本地的Git仓库、提交你的文件到这个仓库中。这之后,你会克隆一个仓库、在仓库之间通过pull和push操作来交换代码的修改。注释(以#开头)解释了命令的具体含义

让我们打开命令行开始操作吧

下面创建一些文件,它们会被放到版本控制之中

#Switch to home
cd ~/
# Create a directory
mkdir ~/repo01
# Switch into it
cd repo01
# Create a new directory
mkdir datafiles # Create a few files touch test01 touch test02 touch test03 touch datafiles/data.txt # Put a little text into the first file ls >test01

每个Git仓库都是放置在.git文件夹下.这个目录包含了仓库的所有历史记录,.git/config文件包含了仓库的本地配置。

以下将会创建一个Git仓库,添加文件倒仓库的索引中,提交更改。

# Initialize the local Git repository
git init
# Add all (files and directories) to the Git repository
git add .
# Make a commit of your file to the local repository
git commit -m "Initial commit" # Show the log file git log

通过git diff命令,用户可以查看更改。通过改变一个文件的内容,看看git diff命令输出什么,然后提交这个更改到仓库中

# Make some changes to the file
echo "This is a change" > test01 echo "and this is another change" > test02 # Check the changes via the diff command git diff # Commit the changes, -a will commit changes for modified files # but will not add automatically new files git commit -a -m "These are new changes"

下面会向你展示仓库现有的状态以及过往的提交历史

# Make some changes in the file
echo "This is a new change" > test01 echo "and this is another new change" > test02 # See the current status of your repository # (which files are changed / new / deleted) git status # Show the differences between the uncommitted files # and the last commit in the current branch git diff # Add the changes to the index and commit git add . && git commit -m "More chaanges - typo in the commit message" # Show the history of commits in the current branch git log # This starts a nice graphical view of the changes gitk --all

通过git amend命令,我们可以修改最后提交的的信息

上述的提交信息中存在错误,下面会修改这个错误

git commit --amend -m "More changes - now correct"

如果你删除了一个在版本控制之下的文件,那么使用git add .不会在索引中删除这个文件。需要通过带-a选项的git commit命令和-A选项的git add命令来完成

# Create a file and put it under version control
touch nonsense.txt
git add . && git commit -m "a new file has been created" # Remove the file rm nonsense.txt # Try standard way of committing -> will not work git add . && git commit -m "a new file has been created" # Now commit with the -a flag git commit -a -m "File nonsense.txt is now removed" # Alternatively you could add deleted files to the staging index via git add -A . git commit -m "File nonsense.txt is now removed"

我们将创建一个远端的Git仓库。这个仓库可以存储在本地或者是网络上。

远端Git仓库和标准的Git仓库有如下差别:一个标准的Git仓库包括了源代码和历史信息记录。我们可以直接在这个基础上修改代码,因为它已经包含了一个工作副本。但是远端仓库没有包括工作副本,只包括了历史信息。可以使用--bare选项来创建一个这样的仓库。

为了方便起见,示例中的仓库创建在本地文件系统上

# Switch to the first repository
cd ~/repo01
# 
git clone --bare . ../remote-repository.git# Check the content, it is identical to the .git directory in repo01
ls ~/remote-repository.git

做一些更改,然后将这些更改从你的第一个仓库推送到一个远端仓库

# Make some changes in the first repository
cd ~/repo01# Make some changes in the file
echo "Hello, hello. Turn your radio on" > test01 echo "Bye, bye. Turn your radio off" > test02 # Commit the changes, -a will commit changes for modified files # but will not add automatically new files git commit -a -m "Some changes" # Push the changes git push ../remote-repository.git

除了通过完整的URL来访问Git仓库外,还可以通过git remote add命令为仓库添加一个短名称。当你克隆了一个仓库以后,origin表示所克隆的原始仓库。即使我们从零开始,这个名称也存在。

# Add ../remote-repository.git with the name origin
git remote add origin ../remote-repository.git # Again some changes
echo "I added a remote repo" > test02 # Commit git commit -a -m "This is a test for the new remote origin" # If you do not label a repository it will push to origin git push origin

通过以下命令查看已经存在的远端仓库

# Show the existing defined remote repositories
git remote

通过以下命令在新的目录下创建一个新的仓库

# Switch to home
cd ~
# Make new directory
mkdir repo02# Switch to new directorycd ~/repo02
# Clone
git clone ../remote-repository.git .

通过拉取,可以从其他的仓库中获取最新的更改。在第二个仓库中,做一些更改,然后将更改推送到远端的仓库中。然后第一个仓库拉取这些更改

# Switch to home
cd ~# Switch to second directory
cd ~/repo02
# Make changes
echo "A change" > test01 # Commit git commit -a -m "A change" # Push changes to remote repository # Origin is automatically maintained as we cloned from this repository git push origin # Switch to the first repository and pull in the changes cd ~/repo01 git pull ../remote-repository.git/ # Check the changes less test01

如果在你的工作副本中,你创建了不想被提交的文件,你可以丢弃它。

# Create a new file with content
touch test04
echo "this is trash" > test04 # Make a dry-run to see what would happen # -n is the same as --dry-run git clean -n # Now delete git clean -f

你可以提取老版本的代码,通过提交的ID。git log命令可以查看提交ID

# Switch to home
cd ~/repo01
# Get the log
git log# Copy one of the older commits and checkout the older revision via  译者注:checkout 后加commit id就是把commit的内容复制到index和工作副本中 
git checkout commit_name

如果你还未把更改加入到索引中,你也可以直接还原所有的更改

#Some nonsense change
echo "nonsense change" > test01 # Not added to the staging index. Therefore we can # just checkout the old version #译者注:checkout后如果没有commit id号,就是从index中拷贝数据到工作副本,不涉及commit部分的改变 git checkout test01 # Check the result cat test01 # Another nonsense change echo "another nonsense change" > test01 # We add the file to the staging index git add test01 # Restore the file in the staging index #译者注:复制HEAD所指commit的test01文件到index中 git reset HEAD test01 # Get the old version from the staging index #译者注:复制index中test01到工作副本中 git checkout test01 #译者注,以上两条命令可以合并为git checkout HEAD test01

也可以通过revert命令进行还原操作

# Revert a commit
git revert commit_name

即使你删除了一个未添加到索引和提交的文件,你也可以还原出这个文件

# Delete a file
rm test01
# Revert the deletion
git checkout test01

如果你已经添加一个文件到索引中,但是未提交。可以通过git reset file 命令将这个文件从索引中删除

// Create a file
touch incorrect.txt
// Accidently add it to the index git add . // Remove it from the index git reset incorrect.txt // Delete the file rm incorrect.txt

如果你删除了文件夹且尚未提交,可以通过以下命令来恢复这个文件夹 。译者注:即使已经提交,也可以还原

git checkout HEAD -- your_dir_to_restore

译者注:checkout和reset这两个命令的含义是不同的,可以参阅这篇文章http://marklodato.github.com/visual-git-guide/index-en.html

Git可以使用对历史记录中的任一版本进行标记。这样在后续的版本中就能轻松的找到。一般来说,被用来标记某个发行的版本

可以通过git tag命令列出所有的标记,通过如下命令来创建一个标记和恢复到一个标记

git tag version1.6 -m 'version 1.6'      
git checkout <tag_name>

通过分支,可以创造独立的代码副本。默认的分支叫master。Git消耗很少的资源就能创建分支。Git鼓励开发人员多使用分支

下面的命令列出了所有的本地分支,当前所在的分支前带有*号

git branch 

如果你还想看到远端仓库的分支,可以使用下面的命令

git branch -a

可以通过下面的命令来创建一个新的分支

# Syntax: git branch <name> <hash>
# <hash> in the above is optional 
# if not specified the last commit will be used # If specified the corresponding commit will be used git branch testing # Switch to your new branch git checkout testing # Some changes echo "Cool new feature in this branch" > test01 git commit -a -m "new feature" # Switch to the master branch git checkout master # Check that the content of test01 is the old one cat test01

通过Merge我们可以合并两个不同分支的结果。Merge通过所谓的三路合并来完成。分别来自两个分支的最新commit和两个分支的最新公共commit

可以通过如下的命令进行合并

# Syntax: git merge <branch-name>
git merge testing

一旦合并发生了冲突,Git会标志出来,开发人员需要手工的去解决这些冲突。解决冲突以后,就可以将文件添加到索引中,然后提交更改

删除分支的命令如下:

#Delete branch testing
git branch -d testing
# Check if branch has been deleted
git branch

默认的,Git只会推送匹配的分支的远端仓库。这意味在使用git push命令默认推送你的分支之前,需要手工的推送一次这个分支。

# Push testing branch to remote repository
git push origin testing# Switch to the testing branch
git checkout testing# Some changes
echo "News for you" > test01 git commit -a -m "new feature in branch" # Push all including branch git push

通过这种方式,你可以确定哪些分支对于其他仓库是可见的,而哪些只是本地的分支

如果两个不同的开发人员对同一个文件进行了修改,那么合并冲突就会发生。而Git没有智能到自动解决合并两个修改

在这一节中,我们会首先制造一个合并冲突,然后解决它,并应用到Git仓库中

下面会产生一个合并冲突

# Switch to the first directory
cd ~/repo01
# Make changes
touch mergeconflict.txt
echo "Change in the first repository" > mergeconflict.txt # Stage and commit git add . && git commit -a -m "Will create merge conflict 1" # Switch to the second directory cd ~/repo02 # Make changes touch mergeconflict.txt echo "Change in the second repository" > mergeconflict.txt # Stage and commit git add . && git commit -a -m "Will create merge conflict 2" # Push to the master repository git push # Now try to push from the first directory # Switch to the first directory cd ~/repo01 # Try to push --> you will get an error message git push # Get the changes git pull origin master

Git将冲突放在收到影响的文件中,文件内容如下:

<<<<<<< HEAD
Change in the first repository
=======
Change in the second repository >>>>>>> b29196692f5ebfd10d8a9ca1911c8b08127c85f8

上面部分是你的本地仓库,下面部分是远端仓库。现在编辑这个文件,然后commit更改。另外的,你可以使用git mergetool命令

# Either edit the file manually or use 
git mergetool
# You will be prompted to select which merge tool you want to use
# For example on Ubuntu you can use the tool "meld" # After merging the changes manually, commit them git commit -m "merged changes"

通过rebase命令可以合并多个commit为一个。这样用户push更改到远端仓库的时候就可以先修改commit历史

接下来我们将创建多个commit,然后再将它们rebase成一个commit

# Create a new file
touch rebase.txt# Add it to git
git add . && git commit -m "rebase.txt added to index" # Do some silly changes and commit echo "content" >> rebase.txt git add . && git commit -m "added content" echo " more content" >> rebase.txt git add . && git commit -m "added more content" echo " more content" >> rebase.txt git add . && git commit -m "added more content" echo " more content" >> rebase.txt git add . && git commit -m "added more content" echo " more content" >> rebase.txt git add . && git commit -m "added more content" echo " more content" >> rebase.txt git add . && git commit -m "added more content" # Check the git log message git log

我们合并最后的七个commit。你可以通过如下的命令交互的完成

git rebase -i HEAD~7

这个命令会打开编辑器让你修改commit的信息或者 squash/ fixup最后一个信息

Squash会合并commit信息而fixup会忽略commit信息(待理解)

你也可以对两个分支进行rebase操作。如下所述,merge命令合并两个分支的更改。rebase命令为一个分支的更改生成一个补丁,然后应用这个补丁到另一分支中

使用merge和rebase,最后的源代码是一样的,但是使用rebase产生的commit历史更加的少,而且历史记录看上去更加的线性

# Create new branch 
git branch testing
# Checkout the branch
git checkout testing
# Make some changes
echo "This will be rebased to master" > test01 # Commit into testing branch git commit -a -m "New feature in branch" # Rebase the master git rebase master

在push更改到其他的Git仓库之前,我们需要仔细检查本地分支的commit历史

在Git中,你可以使用本地的commit。开发人员可以利用这个功能方便的回滚本地的开发历史。但是在push之前,需要观察你的本地分支历史,是否其中有些commit历史对其他用户来说是无关的

如果所有的commit历史都跟同一个功能有关,很多情况下,你需要rebase这些commit历史为一个commit历史。

交互性的rebase主要就是做重写commit历史的任务。这样做是安全的,因为commit还没有被push到其它的仓库。这意味着commit历史只有在被push之前被修改

如果你修改然后push了一个已经在目标仓库中存在的commit历史,这看起来就像是你实现了一些别人已经实现的功能

一个补丁指的是一个包含对源代码进行修改的文本文件。你可以将这个文件发送给某人,然后他就可以应用这个补丁到他的本地仓库

下面会创建一个分支,对这个分支所一些修改,然后创建一个补丁,并应用这个补丁到master分支

# Create a new branch
git branch mybranch
# Use this new branch
git checkout mybranch
# Make some changes
touch test05
# Change some content in an existing file
echo "New content for test01" >test01 # Commit this to the branch git add . git commit -a -m "First commit in the branch" # Create a patch --> git format-patch master git format-patch origin/master # This created patch 0001-First-commit-in-the-branch.patch # Switch to the master git checkout master # Apply the patch git apply 0001-First-commit-in-the-branch.patch # Do your normal commit in the master git add . git commit -a -m "Applied patch" # Delete the patch rm 0001-First-commit-in-the-branch.patch

Git允许你设定你自己的Git命令。你可以给你自己常用的命令起一个缩写命令,或者合并几条命令道一个命令上来。

下面的例子中,定义了git add-commit 命令,这个命令合并了git add . -A 和git commit -m 命令。定义这个命令后,就可以使用git add-commit -m "message" 了.

git config --global alias.add-commit '!git add . -A && git commit'

但是非常不幸,截止写这篇文章之前,定义同名命令在msysGit中还没有支持。同名命令不能以!开始。

有时候,你不希望某些文件或者文件夹被包含在Git仓库中。但是如果你把它们加到.gitignore文件中以后,Git会停止跟踪这个文件。但是 它不会将这个文件从仓库中删除。这导致了文件或者文件夹的最后一个版本还是存在于仓库中。为了取消跟踪这些文件或者文件夹,你可以使用如下的命令

# Remove directory .metadata from git repo
git rm -r --cached .metadata
# Remove file test.txt from repo
git rm --cached test.txt

这样做不会将这些文件从commit历史中去掉。如果你想将这些文件从commit历史中去掉,可以参考git filter-branch命令

下面列出了在日常工作中非常有用的Git命令

Table 2. 有用的Git命令

命令描述
git blame filename谁创建了或者是修改了这个文件
git checkout -b mybranch master~1以上上个commit信息为起点,创建一条新的分支

如上所述,我们的操作不需要Git服务。我可以只使用文件系统或者是Git仓库的提供者,像Github或Bitbucket。但是,有时候,拥有一个自己的服务是比较方便的,在ubuntu下安装一个服务相对来说是比较容易的

确定你已经安装了ssh

apt-get install ssh

如果你还没有安装Git服务,安装它

sudo apt-get install git-core

添加一个名为git的用户

sudo adduser git

然后使用git用户进行登陆,创建一个空的仓库

# Login to server
# to test use localhost
ssh git@IP_ADDRESS_OF_SERVER# Create repository
git init --bare example.git

现在你就可以向远端的仓库提交变更了

mkdir gitexample
cd gitexample
git init
touch README
git add README
git commit -m 'first commit' git remote add origin git@IP_ADDRESS_OF_SERVER:example.git git push origin master

Git支持远端的操作。Git支持多种的传输类型,Git自带的协议就叫做git。下面的的命令通过git协议从克隆一个仓库

git clone git@github.com:vogella/gitbook.git

同样的,你可以通过http协议来克隆仓库

# The following will clone via HTTP 
git clone http://vogella@github.com/vogella/gitbook.git

如果你克隆了一个远端仓库,那么原先的仓库就叫做origin

你可以push修改到origin中,通过 git push origin 命令. 当然,push到一个远端的仓库需要对仓库的写权限

你可以通过git remote add name gitrepo 命令添加多个仓库。例如,你可以通过http协议再次添加之前clone过来的仓库:

// Add the https protocol 
git remote add githttp https://vogella@github.com/vogella/gitbook.git

如果你的防火墙屏蔽了出http以外的所有协议,那么使用http协议来获取仓库是非常好的方法。.

Git同样支持通过代理服务器使用http协议。下面的Git命令会展示这一点。你可以为所有的程序设置代理服务器或者只是为Git服务提供。

下面的例子用到了环境变量

# Linux
export http_proxy=http://proxy:8080
# On Windows
# Set http_proxy=http://proxy:8080 git clone http://dev.eclipse.org/git/org.eclipse.jface/org.eclipse.jface.snippets.git # Push back to the origin using http git push origin

下面的例子只是用到了Git的配置

// Set proxy for git globallygit config --global http.proxy http://proxy:8080
// To check the proxy settings git config --get http.proxy // Just in case you need to you can also revoke the proxy settings git config --global --unset http.proxy

除了假设自己的服务,你也可以使用Git服务提供商提供的服务。最流行的Git服务提供网站是GitHub和Bitbucket。它们都提供了有限制的免费服务

可以通过 https://github.com/ 访问GitHub. GitHub上所有的公开仓库都是免费的。如果你想在上面使用私有的仓库,那么就需要付费给GitHub

GitHub需要你创建ssh的公钥私钥。生成一份Ubuntu的公钥私钥可以访问 ssh key creation in Ubuntu,Windows环境可以访问msysgit ssh key generation.

在GitHub上创建一个账户和一个仓库以后。你会收到如何将你的项目上传到GitHUb的指南,其中的命令大致如下:

Global setup:Set up gitgit config --global user.name "Your Name"git config --global user.email your.email@gmail.com Next steps: mkdir gitbook cd gitbook git init touch README git add README git commit -m 'first commit' git remote add origin git@github.com:vogella/gitbook.git git push -u origin master Existing Git Repo? cd existing_git_repo git remote add origin git@github.com:vogella/gitbook.git git push -u origin master 

可以通过 https://bitbucket.org/ 访问Bitbucket. Bitbucket 提供了无限制了公共仓库和只能有五个人访问的私有仓库。如果你需要超过五个人访问私有仓库,就需要付费给Bitbucket

这个教程主要说明Git命令行的使用。完成了这个教程以后,你可能想要找到一个Git的图形工具

Git提供了两个图形工具。 gitk能够展示仓库的历史信息、git gui 让你可以通过编辑器来完成Git操作

Eclipse EGit 项目提供了Git与Eclipse的集成,在最新的Eclipse版本中可以找到

相关文章:

shell基础语法以及监控进程不存在重启

转码 # dos2unix ./test.sh 权限# chmod ax ./test.sh语法 变量 var"111" echo $var echo ${var}运算 no14; no25; let resultno1no2 echo $result;自增自减少 let no let no--[]和let类似 result$[ no1 no2 ] result$[ $no1 5 ] 也可以使用(())&#xff0c;但使…

java md5算法,JAVA实现MD5算法

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼package org.zcq100.Other;public class MD5 {static final int S11 8;static final int S12 13;static final int S13 18;static final int S14 23;static final int S21 7;static final int S22 11;static final int S23 …

Hulu直播服务难点解析(一):系统需求

版权声明&#xff1a;本文为博主原创文章&#xff0c;未经博主允许不得转载。 https://blog.csdn.net/vn9PLgZvnPs1522s82g/article/details/83053654 Hulu在其博客发布了建立直播服务遇到的挑战及解决方案&#xff0c;这对于以前只提供点播服务的系统而言是一次彻底的升级。Li…

Velocity 入门(一)

Velocity是一种Java模版引擎技术&#xff0c;该项目由Apache提出。因为非常好用&#xff0c;和工作中有啥用&#xff0c;所以我在在理简单的入门一下。 网上找了很多教程&#xff0c;写的不是很明白&#xff0c;要么就是全部拷贝下来时候运行不起来。 在这里我来写一份比较完成…

php 魔术方法 多继承,day23:单继承多继承菱形继承__init__魔术方法

原文&#xff1a;https://www.cnblogs.com/libolun/p/13434675.html单继承关于继承的一些基本概念1.什么是子类?什么是父类?如果一个类继承另外一个类&#xff0c;该类叫做子类(衍生类)&#xff0c;被继承的类叫做父类(基类&#xff0c;超类)2.继承的种类:1.单继承 2.多继承3…

最新版IntelliJ IDEA 15开发Java Maven项目

IntelliJ IDEA是最好的java开发IDE之一 下载地址&#xff1a;http://www.jetbrains.com/idea/download/1.安装好之后开始创建项目2.选择Maven类型项目&#xff0c;选择JDK3.设置Maven坐标4.需要给新项目Add Framework support5.选择Java EE项目模板6.初始的网站修改pom.xml文件…

Android APP全面屏适配技术要点

全面屏的概念 为什么先要解释一下全面屏&#xff0c;因为这个词在现在来讲就是一个伪命题。全面屏字面意思就是手机的正面全部都是屏幕&#xff0c;100%的屏占比。但是现在推出所谓“全面屏”手机的厂商没有一个能达到全面的。 那么下面来说一下Android开发领域对全面屏的理解和…

PHP数据库连接池SQL Relay安装使用

SQL Relay按照其官网http://sqlrelay.sourceforge.net/index.html上所说是&#xff1a;A powerful database connection management solution. 翻译为中文也就是说SQL Relay是一个开源的数据库池连接代理服务器。目前SQL Relay支持的数据库很多&#xff1a; SQL Relay supports…

oracle实例由,Oracle数据库和实例

Oracle数据库服务器由一个数据库和至少一个数据库实例组成。 数据库是一组存储数据的文件&#xff0c;而数据库实例是一组管理数据库文件的内存结构。 另外&#xff0c;数据库由后台进程组成。一个数据库和一个实例是紧密相连的&#xff0c;因此术语 - Oracle数据库 通常用来指…

说一说activity

activity与service&#xff0c;provider&#xff0c;receiver并称为 android的四大对象。 而activity&#xff0c;是展现界面的必不可少的组件。我这里有几个问题要问了&#xff0c;他是如何加载&#xff0c;他是如何进行npc的。具体是怎么实现的了。 说道activity的加载&#…

zookeeper脑裂

出现&#xff1a; 在搭建hadoop的HA集群环境后&#xff0c;由于两个namenode的状态不一&#xff0c;当active的namenode由于网络等原因出现假死状态&#xff0c;standby接收不到active的心跳&#xff0c;因此判断active的namenode宕机&#xff0c;但实际上active并没有死亡。此…

C语言编写的PHP框架--yaf入门编程

首先--添加dll&#xff0c;修改php.ini--不同的版本&#xff0c;不同的需求 其次&#xff0c;根据教程http://www.laruence.com/manual/tutorial.firstpage.html#tutorial.directory手动搭建好目录结构 入口文件index.php位置稍作修改--个人习惯 入口文件内容 <?php header…

调试JDK源码-ConcurrentHashMap实现原理

调试JDK源码-一步一步看HashMap怎么Hash和扩容 调试JDK源码-ConcurrentHashMap实现原理 调试JDK源码-HashSet实现原理 调试JDK源码-调试JDK源码-Hashtable实现原理以及线程安全的原因ConcurrentHashMap线程安全的总结是我从源码分析出来的&#xff1a; ConcurrentHashMap所谓线…

oracle某个表丢失,丢失一个控制文件并恢复数据库

只丢失或损坏一个控制文件的情况下来恢复数据库&#xff0c;相对来说简单一点。一般来说&#xff0c;控制文件都需要形成一个多路径冗余策略&#xff0c;来提高数据库的安全性。这样的话只需将完好的控制文件复制一个副本放到丢失或者损坏了的控制文件所在路径的目录下&#xf…

MySQL:一个死锁分析 (未分析出来的死锁)

最近一个朋友给了我一个死锁 没分析出来搞了好几天&#xff0c;但是把以前出现的一个死锁理了一下流程。这里大概记录一下&#xff0c;并且给出朋友的案例。 RC 隔离级别很少出GAP我已经知道的 继承和分裂会出LOCK_GAP这是代码写死的purge线程可能触发页的分裂融合可能触发内部…

经历一次真实的XSS跨站攻击以及应付之策

这是一个线上真实的事情&#xff0c;黑客已经攻破网站&#xff0c;并主动给我们上报了问题的根源以及解决方案还是不错的。1.前端网站某处存在用户评论输入&#xff0c;黑客再此输出跨站脚本&#xff0c;下面的是从数据库查出来的2.后台管理人员如果浏览到这条数据就会触发这个…

在linux中 要删除abc目录,在 Linux 中,要删除 abc 目录及其全部内容的命令为:

【单选题】星子本地人说( )【判断题】音乐的音响,虽然不能直接传达抽象概念,但是却可以通过同构联觉的去描摹围绕着抽象概念的氛围。( )【判断题】专项耐力负荷量度是通过对糖酵解无氧代谢供能能力与非乳酸供能无氧耐力能力的监控实现的。【单选题】电动轮廓仪是根据( )原理制成…

ECHO.js 纯javascript轻量级延迟加载

演示 <!DOCTYPE html> <html lang"zh-CN"> <head> <meta charset"utf-8"> <title>简单的JavaScript图像延迟加载库Echo.js</title> <style> .demo img { width: 736px; height: 490px; background: url(images/…

SQL中的case when then else end用法

2019独角兽企业重金招聘Python工程师标准>>> Case具有两种格式。简单Case函数和Case搜索函数。 --简单Case函数 CASE sexWHEN 1 THEN 男WHEN 2 THEN 女 ELSE 其他 END --Case搜索函数 CASE WHEN sex 1 THEN 男WHEN sex 2 THEN 女 ELSE 其他 END这两种方式&#xf…

linux run文件夹,Linux下运行run文件

比如realplay.run安装方法如下chmod xrealplay.run./realplay.run然后他就会执行安装了&#xff0c;在过程中可能会要求你输入yes或no安装完后就可以用了,chmod实际上是加权限命令。&#xff0b;x表示可以执行chmod[-cfvR][--help][--version]modefile...说明:Linux/Unix的档案…

POJ2796 Feel Good(单调栈)

题意&#xff1a; 给出一列数据&#xff0c;要求一个区间内最小值与区间内数据总和乘积最大值 要点&#xff1a; 还是单调栈&#xff0c;这次我自己写的&#xff0c;先做了几题比较简单的果然还是有效果的&#xff0c;这题也是一样&#xff0c;按点遍历&#xff0c;网上大神做的…

Solr占用CPU持续过高原因查询

线上java进程占用CPU忽高忽低&#xff0c;就是说一下子40%左右&#xff0c;一下子减下去。这台服务器只有Solr&#xff0c;所以估计是Solr在GC。 # jstat -gcutil 2072 2sJVM名词解释参考java内存泄漏的定位与分析 一些术语的中文解释&#xff1a; S0C&#xff1a;年轻…

通过一个案例理解 JWT

原文出自&#xff1a;https://www.pandashen.com JWT 简述 JWT&#xff08;json web token&#xff09;是为了在网络应用环境之间传递声明而基于 json 的开放标准&#xff0c;JWT 的声明一般被采用在身份提供者和服务器提供者间传递被认证的身份信息&#xff0c;以便于从资源服…

gitlab报错 fatal: index-pack failed error: RPC failed; result=18, HTTP code = 200解决方案

gitlab报错 "fatal: index-pack failed error: RPC failed; result18, HTTP code 200"&#xff0c;如下图这个问题网上有些人给出这样的解决方法是不行的&#xff0c; 所谓&#xff1a;git config --globalhttp.postBuffer 24288000 git config --list 最有代表的是…

(10)Spring Boot修改端口号【从零开始学Spring Boot】

Spring boot 默认端口是8080&#xff0c;如果想要进行更改的话&#xff0c;只需要修改applicatoin.properties文件&#xff0c;在配置文件中加入&#xff1a; server.port9090 常用配置&#xff1a; ######################################################## ###EMBEDDED SER…

linux查看文件安全权限,Linux系统下如何查看及修改文件读写权限

查看文件权限的语句&#xff1a;在终端输入:ls -l xxx.xxx (xxx.xxx是文件名)那么就会出现相类似的信息&#xff0c;主要都是这些&#xff1a;-rw-rw-r--一共有10位数其中&#xff1a; 最前面那个 - 代表的是类型中间那三个 rw- 代表的是所有者(user)然后那三个 rw- 代表的是组…

【网摘】检测 iframe 是否加载完成

var iframeSet document.getElementById("iframeSet"); //需要检测的 iframe if(iframeSet.attachEvent) {iframeSet.attachEvent("onload", function() {$("#loading").hide();}); } else {iframeSet.onload function() {$("#loading&q…

Java json转Map,转bean,转Listbean

引用jackson /** * json转Map&#xff0c;转bean&#xff0c;转List<bean> by http://blog.csdn.net/21aspnet/ * 需要jackjson jar包 */ public class JsonUtil {/*** Object转Json*/public static String ObjectToJson(Object value) {try {ObjectMapper mapper new…

JVM实用参数 GC日志

为什么80%的码农都做不了架构师&#xff1f;>>> 原文章地址&#xff1a;http://blog.panaihua.com/archives/151 GC日志是一个很重要的工具&#xff0c;它准确记录了每一次的GC的执行时间和执行结果&#xff0c;通过分析GC日志可以优化堆设置和GC设置&#xff0c;或…

linux 搜索so文件,Linux下查找和安装依赖的.so文件

以解决Webex在Linux下运行问题为例说明查找和安装依赖的.so文件方法&#xff1a;查找依赖的.so文件$ ldd $HOME/.webex/1324/*.so | grep not foundlibgtk-x11-2.0.so.0 > not foundlibgdk-x11-2.0.so.0 > not foundlibXmu.so.6 > not foundlibXtst.so.6 > not fou…