Translations
Info
All page names need to be in English.
en da  de  fr  it  ja  km  nl  ru  zh

Tips and Tricks (Git)

From TYPO3Wiki
Jump to: navigation, search

Gerrit Tricks

If you want to make copy and paste of git commands even more comfortable, make sure to go to settings/prefernces and enable "Use Flash Clipboard Widget", now you have a little button that fills your clipboard with the proper command.

Console Tricks

Colored console output

shell script:
git config --global color.ui auto

Highlight wrong whitespaces in addition:

shell script:
git config --global color.diff.whitespace "red reverse"

Aliases for frequently used commands

You can define numerous aliases for commands or options that you frequently call, the example shows how to define the aliases git hist and git rvmaster

shell script:
git config alias.hist 'log --format="%h %ad | %s%d [%an]" --graph --date=short'
git config alias.rvmaster 'push origin HEAD:refs/for/master'

Current branch in prompt

You can display the current branch and other information in the prompt of your bash command line. It looks like this:

shell script:
user@hostname:~/typo3 (TYPO3_4-4)$

Instructions:

You can additionally display the current state of your branch (like added files, commits, modified files). For an example have a look at the "don't make me think" shell script at [1]

Ignoring Files

The default way to ignore files are .gitignore (per-directory) and .git/info/exclude (per project). You can use a global .gitignore file by specifying it in the global .gitconfig like so:

shell script:
git config --global core.excludesfile ~/.git/.gitignore

TYPO3.CMS history fix

In order to fix "git log" and "git annotate", allowing you to blame past the namespacing changes back in 6.0, you can apply the following fix in your local clone of the TYPO3 CMS Core repository (Packages/TYPO3.CMS):

git fetch https://github.com/helhum/TYPO3.CMS.git 'refs/replace/*:refs/replace/*'

Verify that it worked:

git replace -l --format=long

Should give you:

2aed998db184936bbc2e6c90bbe3680470abc851 (commit) -> eda6c94a5b9ebe9f1bdd42694ea0149f3b83ab99 (commit)

This has to be done only once and will add a "git replace" statement (can be removed again with git replace -d 2aed998db184936bbc2e6c90bbe3680470abc851) so that the history gets "fixed" at the commit where it was broken (during the namespacing migration in the development of 6.0).

Improving your Workflow

Commit Message Template

You can predefine a template for Commit Message, which eases the task of creating them a bit and reminds you about the Commit Message rules.

  • Put the following text into a file outside the repository.
[BUGFIX|FEATURE] 

Description

Resolves: #
Releases: 
  • Configure Git to use the template:
    git config --global commit.template /path/to/the/template-file
    

Multiple Branches

On your development machine, you might want to share parts of the git repository, when dealing with different installations/clones for different TYPO3 versions. This setup is described in Multiple Branch Setup.

Connecting using the HTTPS protocol

In case your firewall blocks connections to Gerrit's port 29418, you can also use HTTPS (port 443).

As the SSL certificate of review.typo3.org is probably not accepted by your system, you have to disable validation of SSL certificates in Git. To do so, add the following line to ~/.bashrc or ~/.bash_profile:

shell script:
export GIT_SSL_NO_VERIFY=1

Reopen your shell after this step.

Add the following lines to your ~/.gitconfig file:

[url "https://review.typo3.org/p/"]
	insteadOf = git://git.typo3.org/
 
[url "https://review.typo3.org/p/"]
	insteadOf = ssh://review.typo3.org:29418/

Cheat sheets

Draft patches

Patches pushed to the refs/drafts/<branchname> refspec (instead of refs/for/<branchname>) are explicitly marked as "Draft", are private, not meant for regular review and cannot be submitted, yet. They can be made public by hitting the "Publish" button in gerrit.