Git: view detailed modification logs of a day

Source: Internet
Author: User
Tags print format svn update using git git commands
Document directory
  • $ Git log-since = 2011-3-24-until = 2011-3-25-P
  • Git Quick Start
  • Code retrieval and global Modification
  • Each operation to change the code
  • Other common commands
  • Git resumes deleted files
$ Git log-since = 2011-3-24-until = 2011-3-25-P

View logs of 2011-3-25, including commit and the Code involved in modification;

Refer to: Workshop

Process: Get the code → update the code to the latest version before each job → modify the code → submit the code to the server

Code retrieval and global Modification

Set User name and email

1 2 
git config --global user.name "My Name" git config --global user.email "my@email.com"

Extract code from the existing git Library

 
git clone git@server:app.git myrepo
Each operation to change the code

Update the local code to the latest version (merge is required to merge the local code)

 
git fetch

Merge the updated code to the local device.

 
git merge

Another method for updating code (GIT pull is a combination of git fetch and git merge commands)

 
git pull

After modifying the code, view the modified content

 
git diff --cached

Add new files to git

 
git add file1 file2 file3

Delete files from git

1 2 
git rm file1 git rm -r dir1

Submit changes

 
git commit -m 'this is memo'

If you want to save the previous git add command, you can directly use

 
git commit -a -m 'this is memo'

The difference between commit and commit-A is that commit-A is equivalent:

  • Step 1: automatically add all changed codes so that all development codes are listed in index file.
  • Step 2: automatically delete files in the index file but not in the work tree
  • Step 3: Execute the commit command to submit

Submit all the modifications to the remote server so that other team members can update the changes.

 
git push
Other common commands

Show commit logs

 
git log

Not only the commit log is displayed, but also the code changes of each commit are displayed.

 
git log -p

Rollback code:

 
git revert HEAD

You can also revert earlier commit, for example:

 
git revert HEAD^

Destroy your modifications

 
git reset --hard

View the differences between the latest version and the previous version (one ^ indicates moving forward to one version)

 
git diff HEAD HEAD^

Merge the branchname branch into the current branch. (If a merge conflict occurs, you must resolve the conflict yourself)

 
git merge branchname

Resolve Conflicts

When the merge command itself cannot resolve the conflict, it puts the work tree in a special State and provides the conflict information to the user, so that the user can solve these problems by themselves. Of course, the code that does not conflict with each other has been registered in the index file by git merge. If you use git diff at this time, only conflicting code information is displayed.

Before you resolve the conflict, the conflicting file will always be marked in the index file. At this time, if you use git commit to submit, git will prompt: filename.txt needs merge

If you use the GIT status command in the event of a conflict, the details of the conflict will be displayed.

After you have resolved the conflict, you can use the following steps to submit:

Step 1 (if you need to add files ):

 
git add file1

Step 2:

 
git commit
Git resumes deleted files

Git pull is extracted from the GIT server and modified locally with merge, which is similar to SVN up. However, it does not work for deleted files and resumes the use of deleted files.

Http://blog.chinaunix.net/space.php? Uid = 20779306 & Do = Blog & id = 1845726:

Git tips: Linux Basics

The previous article introduced the basic concepts and some basic commands of git. This article focuses on the following three parts: personalized customization of your git, cool and clever use of git, and how to open your own open-source project on git hub. Among all the skills, the most important skill is to learn to view git help, because git is a relatively complex version control tool. If you are familiar with its commands, the value brought to you is self-evident, so you must learn to master the golden finger-view git help, after you add '-help' to any git command, the help document of the command is displayed. For example, you can see all the usage methods of the command 'git log. Next, start by dressing up git.

Git makeup

We can use the GIT config command or directly edit ~ /. Gitconfig file (if not, create it) to create a unique git for yourself. We recommend that you directly edit the. gitconfig file in the user directory. Take my local file as an example to describe it one by one. The complete file content is as follows:

[User]

Name = Phoenix

Email = phoenixtoday@gmail.com

[Alias]

CO = checkout

Ci = commit-

St = Status

BR = Branch

Oneline = Log-pretty = oneline-since = '2 Days ago'

Onelog = Log-p-1

[Color]

Status = auto

Branch = auto

Ui = auto

This file contains three parts:

User basic information: you can set your name and email so that your name will be displayed when you submit the code.

Command alias: This is my favorite part in The. gitconfig file. It can greatly reduce the number of times you hit the keyboard (as the saying goes, good programmers are very lazy ). In this file, I set Co as the checkout alias. Next time I use 'git Co new_branch ', I can switch to the new_branch branch, which is concise and elegant; set CI to the alias of commit-a. The-A option indicates that I do not need to add the modified and deleted files to the index using the 'git add' command, in this way, when the command 'git ci-M "message" 'is used, the command 'git add files modified and deleted 'and 'git commit-M "message' are executed consecutively, saving our precious time; the coolest part is the last two lines, which will be described in the following chapters. Git provides many elegant and user-friendly options. If we combine the alias settings, we can use your imagination to make your own git live.

Color: Is it painful to watch diff every time? So why don't we add color to our git? You only need to add the three lines to display the red and green prompts on your console.

Git agility

Now let's talk about the usage and skills of the 'git log', 'git stash ', and 'git formate-patch' commands:

Git log: Unlike SVN, git clones all the code history records locally, which makes the command 'git log' very fast to use, it is also one of the most commonly used git commands. You can add many suffixes when using 'git log. '-P' indicates the specific modification content. For example, 'git log-p' not only prints the submission time, version number, and personnel, the modified part of the code is printed. '-n' n indicates a number, which indicates several specific logs are printed, for example, 'git-p-1' is the same as the onelog alias set in my git configuration file. It indicates that the latest log record and specific modification content are printed; '-since = "Time/date"', '-until = "Time/date"' indicates that you want to find the log records of a specific date segment, for example, 'git log-since = "2 days ago"-until = "1 hour ago" 'indicates that you want to find the log records from two days ago to one hour ago, git is smart enough to convert the time-like English letters like '2 Days ago 'and '1 hour ago' into specific time numbers. Sometimes, you don't want to go through many pages to view all the logs. You just want to see a brief description, so git provides you with a custom print format 'git-pretty = format type ', the formats include full, short, and oneline. For example, 'git log pretty = oneline 'puts the history of each code in one row, which looks simple and clear.

Git Stash: in the first article, I mentioned the problem of using branch to solve the urgent task switchover. In fact, the stash command can also solve this problem well. If you do not want to submit half of the Code that has been completed, but you have to modify an emergency bug, you can use 'git stash 'to submit the code that has not been submitted locally (and on the server) the code is pushed into the GIT stack. At this time, your work interval is exactly the same as the content submitted last time, so you can fix the bug with confidence and wait until the bug is fixed, after the application is submitted to the server, use 'git stash application' to return the previous half of the work. Some may say, Can I press uncommitted code into the Stack multiple times? The answer is yes. After you use the 'git stash 'command multiple times, your stack will be full of uncommitted Code. At this time, you will be confused about which version will be applied back, the 'git stash list' command can print the current git stack information. You only need to find the corresponding version number, for example, you can use 'git stash apply stash @ {1} 'to obtain the job with the specified version number stash @ {1, when you apply all the stacks back, you can use 'git stash clear' to clear the stacks.

Git format-Patch: When you want to submit a piece of code for an open-source project (such as rails), or you want to show the team members a piece of code that you do not want to submit, you still need patch. Git's 'format-patch 'command supports this function well. Let me briefly describe the steps and methods for using this command: first, use the branch command to create a branch; second, modify your code; and third, submit your modifications on the branch; fourth, run the 'git format-patch 'command to generate a patch file, for example, 'git format-patch master-stdout> ~ /Desktop/tmp. Patch 'is the difference between the work Branch and the master, which is stored in '~ In the/desktop 'folder, generate a file named TMP. Patch (another simple version is to use the diff command, such as 'git diff.. Master> ~ /Desktop/tmp. Patch ') to generate the patch file. Then someone else can use the 'git apply 'command to apply the patch, for example, 'git apply ~ /Desktop/tmp. Patch: load the patch to the current work branch.

Git friends

Git usage tips include using Git-included and attached powerful tools, including git SVN, git citool, gitk, and git automatic prompt scripts:

Git SVN: git and SVN can be easily integrated, which greatly reduces the learning cost for migration from SVN to git, this is the first time that I suggest you use git. Git SVN is a built-in git tool. After you install git, you can install it. For example, your team has a SVN server, but you want to use some of the powerful features of git locally, you can still install git and use the branch Function of git, but use the git svn command when updating the Code and submitting the code. Here I will give a brief description of the two most commonly used commands and the two commands that need attention. Other command readers can view them through 'git svn-help: the 'git SVN rebase' command replaces 'svn Update' to update the server code locally. 'git SVN dcommit 'replaces 'svn cies'. Note that, after the Code must be submitted using git locally, use 'git SVN dcommit '. You can easily switch from SVN to git.

Git citool: This is my most frequently used tool. As mentioned in the previous article, git can submit code locally, so you can modify your submission locally, this tool is a visual interface used to modify your local submission. If you enter 'git citool 'in your work interval, the following interface will appear:

 

 

 

You can use it to submit code and append your local modifications to the Code submitted last time. You can also use it to modify the information you submitted last time. This tool can greatly help you complete tasks that were previously impossible for SVN.

Gitk: a tool used to view the status of the trunk or branch. It is mainly used to observe the status of the branches of the entire project. You can view the status of the branches using the 'gitk' command, in this article, we will give you a simple explanation.

Git's automatic prompt Script: It is Shawn O. pearce writes shell scripts to make it easier for git to use, you can find a script called gitcompletion in the http://gitweb.hawaga.org.uk/, download it, and configure it as instructed in the script, you have the GIT automatic prompt function (press the tab key after you press some git commands), and with this script, you can also see the branch under which you are currently working. The only disadvantage is that it only supports Linux, UNIX, and Mac operating systems (we recommend that you use MAC for development)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.