Home Computing How to use Git-How to record changes in the repository-

How to use Git-How to record changes in the repository-

by Yasir Aslam
0 comment

If there is a change in the file in the folder that is versioned by git, check how to reflect it in the repository while actually using Git Bash.

table of contents

1. File management flow

2. Working directory

3. Staging area (index)

4. Repository

1. File management flow

In ” How to use Git-Create and commit repository-“, we confirmed the operation from initialization of repository to commit. When managing versions with Git, it is necessary to properly grasp the following three locations (states).

● “Working directory”
● “Staging area”
● “Repository”

To summarize briefly, the “working directory” is the place to add, create, and edit files, the “staging area” is the area to temporarily store changed files, and the “repository” is the place to finally store files. is. In Git, when a file etc. in the working directory is edited / added, the addition / editing information is first registered in the staging area without committing (saving) directly to the repository. By making good use of the staging area, you can commit only the files that need to be committed to the repository in the working directory, or reflect only the edit history of a part of the file in the repository. Let’s use “Git Bash” to check the specific state.2. Working directory

Add / edit files based on the “Git-ws” folder registered in the repository in ” How to use Git-Create and commit repository-“. There is one file (git-sample.txt) registered in the repository in the “Git-ws” folder. The folder where the repository is initialized by “git init” becomes the “working directory”.
Select [All apps]-> [Git]-> [Git Bash] from the Windows Start menu to start the terminal. Enter “git log” at the prompt to see the history of the current file.

● [git log]

$ git log
commit 83e280f9e3d6959c75674eef5fa271e981aa25a1
Author: Taro Yamada<[email protected]>
Date: Tue Feb 21 00:00:00 2017 +0900

projectX version1.0
</[email protected]>

3. Staging area (index)

Let’s add a file to the “Git-ws” working directory. Add a text file called “git-sample2.txt” to your “Git-ws” working directory. In this state, hit the “git status” command.

● [git status]

$ git status
On branch master
Untracked files:
(use “git add”… “to include in what will be committed)

git-sample2.txt

nothing added to commit but untracked files present (use” git add “to track)

“Untracked files:” means untracked files. In Git, when a file is added or changed to the folder where the repository is created, you can check the information with “git status”. The English message means “There is a file (git-sample2.txt) that is not tracked by Git, so please track the file you intend to commit with [git add <filename>]”. Now, let’s track the newly added file “git-sample2.txt” with the add command of git according to the message.

● [git add]

$ git add git-sample2.txt

Let’s check the status of the file.

● [git status]

$ git status
On branch master
Changes to be committed:
(use “git reset HEAD”… “to unstage)

new file: git-sample2.txt

The add command is a command to register new files and changes before committing in the staging area. A new file: git-sample2.txt has been added to the staging area. You can also use the “git reset …” command to “unstage” the English text in parentheses. This means that files registered in the staging area (= files in the staging area) can also be unstaged with the “git reset …” command.

4. Repository

Now that the newly added file is ready to commit, let’s type the command “git commit -m” projextX version 1.1 “”.

● [git status]

$ git status
On branch master
nothing to commit, working tree clean

The commit command is a command to register the information of the file in the staging area in the “repository”. If there are other files to add but they are not in the staging area, they will not be registered in the repository.
Let’s see the current file information with the “git log” command.

● [git status]

$ git log
commit 3610105f0da8d684075a0626cc7c0be03773969f
Author: Taro Yamada<[email protected]>
Date: Tue Feb 21 00:02:02 2017 +0900

projectX version1.0

commit 83e280f9e3d6959c75674eef5fa271e981aa25a1
Author: Taro Yamada<[email protected]>
Date: Tue Feb 21 00:00:00 2017 +0900

projectX version1.0
</[email protected]></[email protected]>

You can check the change history of the two files with the “log command”.

[Related document] How to install Git on Windows
[Related document] How to use Git for Windows-Preparation-
[Related document] How to use Git-Create and commit repository- [Related document] How to cancel git add [ Related
document] ] Git command ~ Cancel commit ~ [Related document] How to create a branch with Git

You may also like

Leave a Comment