Skip to content

Commit

Permalink
Innit text file
Browse files Browse the repository at this point in the history
  • Loading branch information
vnwildman committed Dec 4, 2010
1 parent eec6cc5 commit bb96d20
Show file tree
Hide file tree
Showing 11 changed files with 1,820 additions and 0 deletions.
211 changes: 211 additions & 0 deletions vi/basic.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
== Basic Tricks ==

Thay vì lao vào cả "biển lệnh" của Git, hãy sử dụng các ví dụ cơ bản để bắt đầu.
Mặc dù chúng rất đơn giản, nhưng tất cả chúng đều rất hữu dụng.
Quả thực là vậy, trong tháng đầu tiên sử dụng Git Tôi chưa bao giờ vượt qua những gì nói trong chương này.

=== Ghi lại State ===

About to attempt something drastic? Trước khi làm điều đó, thực hiện với tất cả các tệp tin trong thư mục hiện hành bằng cách:

$ git init
$ git add .
$ git commit -m "My first backup"

Now if your new edits go awry, restore the pristine version:

$ git reset --hard

To save the state again:

$ git commit -a -m "Another backup"

=== Thêm, Xóa, Đổi tên ===

The above only keeps track of the files that were present when you first ran *git add*. If you add new files or subdirectories, you'll have to tell Git:

$ git add readme.txt Documentation

Tương tự như vậy, nếu bạn muốn Git bỏ qua các tệp tin nào đó:

$ git rm kludge.h obsolete.c
$ git rm -r incriminating/evidence/

Git xóa bỏ những tệp tin nếu như bạn chưa làm.

Renaming a file is the same as removing the old name and adding the new name. There's also the shortcut *git mv* which has the same syntax as the *mv* command. Ví dụ:

$ git mv bug.c feature.c

=== Advanced Undo/Redo ===

Đôi khi bạn chỉ muốn quay trở lại và bỏ đi những thay đổi trong quá khứ tại một thời điểm nào đó bởi vì chúng tất cả đã sai. Thì:

$ git log

hiển thị cho bạn danh sách các lần commit gần đây cùng với giá trị băm SHA1:

----------------------------------
commit 766f9881690d240ba334153047649b8b8f11c664
Author: Bob <[email protected]>
Date: Tue Mar 14 01:59:26 2000 -0800

Replace printf() with write().

commit 82f5ea346a2e651544956a8653c0f58dc151275c
Author: Alice <[email protected]>
Date: Thu Jan 1 00:00:00 1970 +0000

Initial commit.
----------------------------------

Chỉ vài ký tự của giá trị băm là đủ để chỉ ra một commit;
một cách khác là chép và dán giá trị băm. Gõ:

$ git reset --hard 766f

to restore the state to a given commit and erase all newer commits from the record permanently.

Other times you want to hop to an old state briefly. In this case, type:

$ git checkout 82f5

This takes you back in time, while preserving newer commits. However, like time travel in a science-fiction movie, if you now edit and commit, you will be in an alternate reality, because your actions are different to what they were the first time around.

This alternate reality is called a 'branch', and <<branch,we'll have more to say about this later>>. For now, just remember that

$ git checkout master

will take you back to the present. Also, to stop Git complaining, always
commit or reset your changes before running checkout.

To take the computer game analogy again:

- *`git reset --hard`*: load an old save and delete all saved games newer than the one just loaded.

- *`git checkout`*: load an old game, but if you play on, the game state will deviate from the newer saves you made the first time around. Any saved games you make now will end up in a separate branch representing the alternate reality you have entered. <<branch,We deal with this later>>.

You can choose only to restore particular files and subdirectories by appending them after the command:

$ git checkout 82f5 some.file another.file

Take care, as this form of *checkout* can silently overwrite files. To
prevent accidents, commit before running any checkout command, especially when
first learning Git. In general, whenever you feel unsure about any operation, Git command or not, first run *git commit -a*.

Bạn không thích việc cắt dán ư? Hãy sử dụng:

$ git checkout :/"My first b"

to jump to the commit that starts with a given message.
You can also ask for the 5th-last saved state:

$ git checkout master~5

=== Reverting ===

In a court of law, events can be stricken from the record. Likewise, you can pick specific commits to undo.

$ git commit -a
$ git revert 1b6d

will undo just the commit with the given hash. The revert is recorded as a new
commit, which you can confirm by running *git log*.

=== Changelog Generation ===

Some projects require a http://en.wikipedia.org/wiki/Changelog[changelog].
Generate one by typing:

$ git log > ChangeLog

=== Tải về các Tệp tin ===

Lấy về một bản sao của một dự án quản lý bằng Git bằng cách gõ:

$ git clone git://server/path/to/files

Ví dụ, để lấy tất cả các tệp tin mà tôi đã dùng để tạo ra cho trang mạng này là:

$ git clone git://git.or.cz/gitmagic.git

Chúng ta sẽ có nhiều điều để nói về lệnh *clone* sớm thôi.

=== The Bleeding Edge ===

Nếu bạn đã tải về một bản sao của một dự án sử dụng *git clone*, bạn có thể nâng cấp lên phiên bản cuối cùng với lệnh:

$ git pull

=== Instant Publishing ===

Suppose you've written a script you'd like to share with others. You could just tell them to download from your computer, but if they do so while you're improving the script or making experimental changes, they could wind up in trouble. Of course, this is why release cycles exist. Developers may work on a project frequently, but they only make the code available when they feel it is presentable.

Thực hiện điều này với Git, trong thư mục nơi script của bạn nằm trong:

$ git init
$ git add .
$ git commit -m "First release"

Sau đó nói với những người sử dụng hãy chạy:

$ git clone your.computer:/path/to/script

để tải script về. This assumes they have ssh access. If not, run *git daemon* and tell your users to instead run:

$ git clone git://your.computer/path/to/script

From now on, every time your script is ready for release, execute:

$ git commit -a -m "Next release"

and your users can upgrade their version by changing to the directory containing your script and typing:

$ git pull

Your users will never end up with a version of your script you don't want them to see.

=== What Have I Done? ===

Find out what changes you've made since the last commit with:

$ git diff

Hay từ hôm qua:

$ git diff "@{yesterday}"

Or between a particular version and 2 versions ago:

$ git diff 1b6d "master~2"

In each case the output is a patch that can be applied with *git apply*.
Try also:

$ git whatchanged --since="2 weeks ago"

Often I'll browse history with http://sourceforge.net/projects/qgit[qgit]
instead, due to its slick photogenic interface, or
http://jonas.nitro.dk/tig/[tig], a text-mode interface that works well over
slow connections. Alternatively, install a web server, run *git instaweb* and
fire up any web browser.

=== Bài tập===

Let A, B, C, D be four successive commits where B is the same as A except some files have been removed. We want to add the files back at D. How can we do this?

There are at least three solutions. Assuming we are at D:

1. The difference between A and B are the removed files. We can create a patch representing this difference and apply it:

$ git diff B A | git apply

2. Since we saved the files back at A, we can retrieve them:

$ git checkout A foo.c bar.h

3. We can view going from A to B as a change we want to undo:

$ git revert B

Lựa chọn nào là tốt nhất? Cái nào bạn thích nhất. It is easy to get what you want with Git, and often there are many ways to get it.
Loading

0 comments on commit bb96d20

Please sign in to comment.