Git实战篇

准备工作

对于gitssh的安装方法、配置,还有git和ssh的一些常用命令可见git常用命令解说》和《ssh常用用法小结在此越过。 需要说明的是,就目前工作所需的要点稍微较少,可能个人原因,比如对Git和SSH的了解甚少,还需各位指点江山。SSH主要就是用来远程登录服务器,无非就ssh name@remoteserver之后就是输入密码:XXX。而git命令要用到的比较多,需要熟知可以通过man git查看git指令中的意义。


创建库repository---git init

先找一块比较干净的地方坐下,通过指令:

mkdir MyRepository#创建目录
cd MyRepository/#进入目录
MyRepository$ git init#创建一个库

输入上面一条语句成功后,会打印出:Initialized empty Git repository in /home/hunter/MyRepository/.git/

分支---git branch

倘若你还没有创建一个库,或者还没有进入一个库中,你输入git branch命令,会显示出“fatal: Not a git repository (or any of the parent directories): .git”,因为此条命令需要在库中才会有意义。还有,就是初次创建一个库,即刚刚git init后,需要进行一次提交后,git branch才不会显示为空和git branch xxx创建分支也不会出现“fatal: Not a valid object name: 'master'.”。可以当前目录(即你git init的目录)创建一个README文件,在当前目录下就一个README文件,其他隐藏了。如图:

依次进行以下操作,即可以git brach 查看分支,创建分支了,



以上指令中,用到git status(查看当前状态)、git add XXX(添加文件或者文件夹)、git commit(提交),根据git status提示的操作一步步的往下就可以,还有就是一些细节问题,目前不知如何操作,如:提交失误等问题。

^_^,可以创建分支了,

创建了分支good。

添加一个文件夹到库中---git add

将文件夹拷贝至库的当前目录下,

输入git status 

hunter@ubuntu:~/MyRepository$ git status
# On branch good
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#    MenuO/
nothing added to commit but untracked files present (use "git add" to track)

输入git add
hunter@ubuntu:~/MyRepository$ git add MenuO/
输入git status

hunter@ubuntu:~/MyRepository$ git status
# On branch good
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#    new file:   MenuO/.classpath
#    new file:   MenuO/.project
#    new file:   MenuO/AndroidManifest.xml
#    new file:   MenuO/bin/AndroidManifest.xml
#    new file:   MenuO/bin/MenuO.apk
#    new file:   MenuO/bin/classes.dex
#    new file:   MenuO/bin/classes/info/kagyou/menuo/BuildConfig.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/CircleImageView.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/CircleLayout$FlingRunnable.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/CircleLayout$MyGestureListener.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/CircleLayout$OnCenterClickListener.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/CircleLayout$OnItemClickListener.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/CircleLayout$OnItemSelectedListener.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/CircleLayout.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/MainActivity.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/R$attr.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/R$dimen.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/R$drawable.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/R$id.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/R$layout.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/R$menu.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/R$string.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/R$style.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/R$styleable.class
#    new file:   MenuO/bin/classes/info/kagyou/menuo/R.class
#    new file:   MenuO/bin/dexedLibs/android-support-v4-506bdae8b36b0901941aceadf14596e5.jar
#    new file:   MenuO/bin/jarlist.cache
#    new file:   MenuO/bin/res/drawable-hdpi/ic_launcher.png
#    new file: 
......................................>

输入git comit和git status

hunter@ubuntu:~/MyRepository$ git commit -m "add menuo"
[good c8a1dd4] add menuo
 67 files changed, 1372 insertions(+)
 create mode 100644 MenuO/.classpath
 create mode 100644 MenuO/.project
 create mode 100644 MenuO/AndroidManifest.xml
 create mode 100644 MenuO/bin/AndroidManifest.xml
 create mode 100644 MenuO/bin/MenuO.apk
 create mode 100644 MenuO/bin/classes.dex
 create mode 100644 MenuO/bin/classes/info/kagyou/menuo/BuildConfig.class
 create mode 100644 MenuO/bin/classes/info/kagyou/menuo/CircleImageView.class
 crea...............................................................
hunter@ubuntu:~/MyRepository$ git status
# On branch good
nothing to commit (working directory clean)

添加成功!

本地代码合并---git merge

通过工具qgit打开一个库,里面有分支master和good,未对其进行合并之前的图如下:

good分支:

master分支:


输入git merge good

QGIT中的截图如下:

这只是在本地中合并,未有在服务器中试过,或者服务器与本地合并。

服务器代码到服务器中---git pull

代码已经放置在ServerRep库中。

本地代码放置服务器中---git pull

ssh登录服务器,创建一个库,cd进去。

服务器代码放置本地机上---git pull

在本地机上进入一个库,

本地到本地

其实以上几个动作都差不多,不确定也许会出现一定的错误,在经过多次的操作之后,也许执行一个命令之后就不会成功。

改变一个库中的代码,再将代码上传至另外一个库中

在本地库中改了一个java代码,如:

/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.alarmclock;

import com.android.deskclock.DeskClock;
import com.android.deskclock.R;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;

/**
 * Simple widget to show analog clock.
 */
public class AnalogAppWidgetProvider extends BroadcastReceiver {
    static final String TAG = "AnalogAppWidgetProvider";

hdhfkahdkhjdkfaj//第一处
jkdfkjaj//第二处
//第三处
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();

        if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
            RemoteViews views = new RemoteViews(context.getPackageName(),
                    R.layout.analog_appwidget);

            views.setOnClickPendingIntent(R.id.analog_appwidget,
                    PendingIntent.getActivity(context, 0,
                        new Intent(context, DeskClock.class), 0));

            int[] appWidgetIds = intent.getIntArrayExtra(
                    AppWidgetManager.EXTRA_APPWIDGET_IDS);

            AppWidgetManager gm = AppWidgetManager.getInstance(context);
            gm.updateAppWidget(appWidgetIds, views);
        }
    }
}
nihaoya j//第四处


保存该文件后,在本地库中进行如下操作:

在其他库中,即要将代码上传的地方,执行

成功之后,可以发现两个库中的代码都是一致的。在多次的操作过程中也许会出现很多莫名其妙的问题,由于自己对此不是很熟,只能用莫名其妙来形容,对此这些都是些较为简单的操作,还有,很多关于git的应用,还需好好学习!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值