| Start | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Good commit messages It is important for someone traversing through the Better messages may look like: Whereas the following messages would not be quite as useful: A way to test if a commit message is written in the correct mood is to replace the blank with the message and see if it makes sense: If I add this commit, I will ___ to my repository. The seven rules of a great git commit message
|
||||||||||||||||||||||
| Amending a commit If your latest commit is not published yet (not pushed to an upstream repository) then you can amend your commit. This will put the currently staged changes onto the previous commit. Note: This can also be used to edit an incorrect commit message. It will bring up the default editor (usually To specify the commit message inline: Or to use the previous commit message without changing it: Amending updates the commit date but leaves the author date untouched. You can tell git to refresh the information. You can also change the author of the commit with: Note: Be aware that amending the most recent commit replaces it entirely and the previous commit is removed from the branch's history. This should be kept in mind when working with public repositories and on branches with other collaborators. This means that if the earlier commit had already been pushed, after amending it you will have to |
||||||||||||||||||||||
| Committing without opening an editor Git will usually open an editor (like Your commit message can go over multiple lines: Alternatively, you can pass in multiple |
||||||||||||||||||||||
Stage and commit changes The basicsAfter making changes to your source code, you should stage those changes with Git before you can commit them. For example, if you change This tells git that you want to add the files to the next commit you do. Then, commit your changes with Note that this will open a text editor, which is often (opens new window) vim (opens new window). If you are not familiar with vim, you might want to know that you can press Commit messages often follow some specific formatting rules, see Good commit messages (opens new window) for more information. ShortcutsIf you have changed a lot of files in the directory, rather than listing each one of them, you could use: Or to add all changes, not including files that have been deleted, from the top-level directory and subdirectories: Or to only add files which are currently tracked ("update"): If desired, review the staged changes: Finally, commit the changes: Alternately, if you have only modified existing files or deleted files, and have not created any new ones, you can combine the actions of Note that this will stage all modified files in the same way as Sensitive dataYou should never commit any sensitive data, such as passwords or even private keys. If this case happens and the changes are already pushed to a central server, consider any sensitive data as compromised. Otherwise, it is possible to remove such data afterwards. A fast and easy solution is the usage of the "BFG Repo-Cleaner": https://rtyley.github.io/bfg-repo-cleaner/ (opens new window). The command |
||||||||||||||||||||||
| Committing changes directly Usually, you have to use If you would like to also add a commit message you would do: Also, you can join two flags: You don't necessarily need to commit all files at once. Omit the For directly committing more than one specific file, you can specify one or multiple files, directories and patterns as well: |
||||||||||||||||||||||
| Creating an empty commit Generally speaking, empty commits (or commits with state that is identical to the parent) is an error. However, when testing build hooks, CI systems, and other systems that trigger off a commit, it's handy to be able to easily create commits without having to edit/touch a dummy file. The
|
||||||||||||||||||||||
| Committing on behalf of someone else If someone else wrote the code you are committing, you can give them credit with the You can also provide a pattern, which Git will use to search for previous authors: In this case, the author information from the most recent commit with an author containing "John" will be used. On GitHub, commits made in either of the above ways will show a large author's thumbnail, with the committer's smaller and in front: |
||||||||||||||||||||||
| Selecting which lines should be staged for committing Suppose you have many changes in one or more files but from each file you only want to commit some of the changes, you can select the desired changes using: or Each of your changes will be displayed individually, and for each change you will be prompted to choose one of he following options: This will stage the parts of the files you choose. Then you can commit all the staged changes like this: The changes that were not staged or committed will still appear in your working files, and can be committed later if required. Or if the remaining changes are unwanted, they can be discarded with: Apart from breaking up a big change into smaller commits, this approach is also useful for reviewing what you are about to commit. By individually confirming each change, you have an opportunity to check what you wrote, and can avoid accidentally staging unwanted code such as println/logging statements. |
||||||||||||||||||||||
| Commiting changes in specific files You can commit changes made to specific files and skip staging them using Or you can first stage the files: and commit them later: |
||||||||||||||||||||||
GPG signing commits Your ID is a alphanumeric 16-digit code following the first forward-slash. |
||||||||||||||||||||||
Committing at a specific date The To force the commit date too: The date parameter accepts the flexible formats as supported by GNU date, for example: When the date doesn't specify time, the current time will be used and only the date will be overridden. |
||||||||||||||||||||||
| Amending the time of a commit You cam amend the time of a commit using or even |
||||||||||||||||||||||
| Amending the author of a commit If you make a commit as the wrong author, you can change it, and then amend Syntax
Parameters
|
Read Article
https://develop.horje.com/learn/1434/reference