Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atualiza apêndices (em inglês) (rebase master) #77

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions A-git-in-other-environments.asc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[#A-git-in-other-environments]
[[A-git-in-other-environments]]
[appendix]
== Git in Other Environments

Expand All @@ -11,8 +11,11 @@ include::book/A-git-in-other-environments/sections/guis.asc[]

include::book/A-git-in-other-environments/sections/visualstudio.asc[]

include::book/A-git-in-other-environments/sections/eclipse.asc[]
include::book/A-git-in-other-environments/sections/visualstudiocode.asc[]

include::book/A-git-in-other-environments/sections/jetbrainsides.asc[]

include::book/A-git-in-other-environments/sections/sublimetext.asc[]

include::book/A-git-in-other-environments/sections/bash.asc[]

Expand Down
10 changes: 8 additions & 2 deletions B-embedding-git.asc
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
[#B-embedding-git]
[[B-embedding-git-in-your-applications]]
[appendix]
== Embedding Git in your Applications

If your application is for developers, chances are good that it could benefit from integration with source control.
Even non-developer applications, such as document editors, could potentially benefit from version-control features, and Git's model works very well for many different scenarios.

If you need to integrate Git with your application, you have essentially three choices: spawning a shell and using the Git command-line tool; Libgit2; and JGit.
If you need to integrate Git with your application, you have essentially two options: spawn a shell and call the `git` command-line program, or embed a Git library into your application.
Here we'll cover command-line integration and several of the most popular embeddable Git libraries.

include::book/B-embedding-git/sections/command-line.asc[]

include::book/B-embedding-git/sections/libgit2.asc[]

include::book/B-embedding-git/sections/jgit.asc[]

include::book/B-embedding-git/sections/go-git.asc[]

include::book/B-embedding-git/sections/dulwich.asc[]

294 changes: 169 additions & 125 deletions C-git-commands.asc

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions book/A-git-in-other-environments/sections/bash.asc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ First, you need to get a copy of the `contrib/completion/git-completion.bash` fi
Copy it somewhere handy, like your home directory, and add this to your `.bashrc`:

[source,console]
-----
----
. ~/git-completion.bash
-----
----

Once that's done, change your directory to a Git repository, and type:

Expand All @@ -27,16 +27,16 @@ This can be as simple or complex as you want, but there are generally a few key
To add these to your prompt, just copy the `contrib/completion/git-prompt.sh` file from Git's source repository to your home directory, add something like this to your `.bashrc`:

[source,console]
-----
----
. ~/git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
export PS1='\w$(__git_ps1 " (%s)")\$ '
-----
----

The `\w` means print the current working directory, the `\$` prints the `$` part of the prompt, and `__git_ps1 " (%s)"` calls the function provided by `git-prompt.sh` with a formatting argument.
Now your bash prompt will look like this when you're anywhere inside a Git-controlled project:

.Customized `bash` prompt.
image::images/git-bash.png[Customized `bash` prompt.]
.Customized `bash` prompt
image::images/git-bash.png[Customized `bash` prompt]

Both of these scripts come with helpful documentation; take a look at the contents of `git-completion.bash` and `git-prompt.sh` for more information.
10 changes: 0 additions & 10 deletions book/A-git-in-other-environments/sections/eclipse.asc

This file was deleted.

69 changes: 34 additions & 35 deletions book/A-git-in-other-environments/sections/guis.asc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ But plain text isn't the best choice for all tasks; sometimes a visual represent

It's important to note that different interfaces are tailored for different workflows.
Some clients expose only a carefully curated subset of Git functionality, in order to support a specific way of working that the author considers effective.
When viewed in this light, none of these tools can be called ``better'' than any of the others, they're simply more fit for their intended purpose.
When viewed in this light, none of these tools can be called "`better`" than any of the others, they're simply more fit for their intended purpose.
Also note that there's nothing these graphical clients can do that the command-line client can't; the command-line is still where you'll have the most power and control when working with your repositories.

==== `gitk` and `git-gui`
Expand All @@ -31,8 +31,8 @@ Gitk accepts many command-line options, most of which are passed through to the
Probably one of the most useful is the `--all` flag, which tells gitk to show commits reachable from _any_ ref, not just HEAD.
Gitk's interface looks like this:

.The `gitk` history viewer.
image::images/gitk.png[The `gitk` history viewer.]
.The `gitk` history viewer
image::images/gitk.png[The `gitk` history viewer]

On the top is something that looks a bit like the output of `git log --graph`; each dot represents a commit, the lines represent parent relationships, and refs are shown as colored boxes.
The yellow dot represents HEAD, and the red dot represents changes that are yet to become a commit.
Expand All @@ -43,14 +43,14 @@ In between is a collection of controls used for searching history.
It, too, is easiest to invoke from the command line:

[source,console]
-----
----
$ git gui
-----
----

And it looks something like this:

.The `git-gui` commit tool.
image::images/git-gui.png[The `git-gui` commit tool.]
.The `git-gui` commit tool
image::images/git-gui.png[The `git-gui` commit tool]

On the left is the index; unstaged changes are on top, staged changes on the bottom.
You can move entire files between the two states by clicking on their icons, or you can select a file for viewing by clicking on its name.
Expand All @@ -59,35 +59,34 @@ At top right is the diff view, which shows the changes for the currently-selecte
You can stage individual hunks (or individual lines) by right-clicking in this area.

At the bottom right is the message and action area.
Type your message into the text box and click ``Commit'' to do something similar to `git commit`.
You can also choose to amend the last commit by choosing the ``Amend'' radio button, which will update the ``Staged Changes'' area with the contents of the last commit.
Then you can simply stage or unstage some changes, alter the commit message, and click ``Commit'' again to replace the old commit with a new one.
Type your message into the text box and click "`Commit`" to do something similar to `git commit`.
You can also choose to amend the last commit by choosing the "`Amend`" radio button, which will update the "`Staged Changes`" area with the contents of the last commit.
Then you can simply stage or unstage some changes, alter the commit message, and click "`Commit`" again to replace the old commit with a new one.

`gitk` and `git-gui` are examples of task-oriented tools.
Each of them is tailored for a specific purpose (viewing history and creating commits, respectively), and omit the features not necessary for that task.

==== GitHub for macOS and Windows

==== GitHub for Mac and Windows

(((GitHub for Mac)))(((GitHub for Windows)))
GitHub has created two workflow-oriented Git clients: one for Windows, and one for Mac.
(((GitHub for macOS)))(((GitHub for Windows)))
GitHub has created two workflow-oriented Git clients: one for Windows, and one for macOS.
These clients are a good example of workflow-oriented tools – rather than expose _all_ of Git's functionality, they instead focus on a curated set of commonly-used features that work well together.
They look like this:

.GitHub for Mac.
image::images/github_mac.png[GitHub for Mac.]
.GitHub for macOS
image::images/github_mac.png[GitHub for macOS]

.GitHub for Windows.
image::images/github_win.png[GitHub for Windows.]
.GitHub for Windows
image::images/github_win.png[GitHub for Windows]

They are designed to look and work very much alike, so we'll treat them like a single product in this chapter.
We won't be doing a detailed rundown of these tools (they have their own documentation), but a quick tour of the ``changes'' view (which is where you'll spend most of your time) is in order.
We won't be doing a detailed rundown of these tools (they have their own documentation), but a quick tour of the "`changes`" view (which is where you'll spend most of your time) is in order.

* On the left is the list of repositories the client is tracking; you can add a repository (either by cloning or attaching locally) by clicking the ``+'' icon at the top of this area.
* On the left is the list of repositories the client is tracking; you can add a repository (either by cloning or attaching locally) by clicking the "`+`" icon at the top of this area.
* In the center is a commit-input area, which lets you input a commit message, and select which files should be included.
(On Windows, the commit history is displayed directly below this; on Mac, it's on a separate tab.)
On Windows, the commit history is displayed directly below this; on macOS, it's on a separate tab.
* On the right is a diff view, which shows what's changed in your working directory, or which changes were included in the selected commit.
* The last thing to notice is the ``Sync'' button at the top-right, which is the primary way you interact over the network.
* The last thing to notice is the "`Sync`" button at the top-right, which is the primary way you interact over the network.

[NOTE]
====
Expand All @@ -97,12 +96,12 @@ While they're designed to highlight GitHub's service and recommended workflow, t

===== Installation

GitHub for Windows can be downloaded from https://windows.github.com[], and GitHub for Mac from https://mac.github.com[].
GitHub for Windows can be downloaded from https://windows.github.com[], and GitHub for macOS from https://mac.github.com[].
When the applications are first run, they walk you through all the first-time Git setup, such as configuring your name and email address, and both set up sane defaults for many common configuration options, such as credential caches and CRLF behavior.

Both are ``evergreen'' – updates are downloaded and installed in the background while the applications are open.
Both are "`evergreen`" – updates are downloaded and installed in the background while the applications are open.
This helpfully includes a bundled version of Git, which means you probably won't have to worry about manually updating it again.
On Windows, the client includes a shortcut to launch Powershell with Posh-git, which we'll talk more about later in this chapter.
On Windows, the client includes a shortcut to launch PowerShell with Posh-git, which we'll talk more about later in this chapter.

The next step is to give the tool some repositories to work with.
The client shows you a list of the repositories you have access to on GitHub, and can clone them in one step.
Expand All @@ -111,25 +110,25 @@ If you already have a local repository, just drag its directory from the Finder
===== Recommended Workflow

Once it's installed and configured, you can use the GitHub client for many common Git tasks.
The intended workflow for this tool is sometimes called the ``GitHub Flow.''
We cover this in more detail in <<ch06-github#r_github_flow>>, but the general gist is that (a) you'll be committing to a branch, and (b) you'll be syncing up with a remote repository fairly regularly.
The intended workflow for this tool is sometimes called the "`GitHub Flow.`"
We cover this in more detail in <<ch06-github#ch06-github_flow>>, but the general gist is that (a) you'll be committing to a branch, and (b) you'll be syncing up with a remote repository fairly regularly.

Branch management is one of the areas where the two tools diverge.
On Mac, there's a button at the top of the window for creating a new branch:
On macOS, there's a button at the top of the window for creating a new branch:

.``Create Branch'' button on Mac.
image::images/branch_widget_mac.png[``Create Branch'' button on Mac.]
."`Create Branch`" button on macOS
image::images/branch_widget_mac.png[Create Branch button on macOS]

On Windows, this is done by typing the new branch's name in the branch-switching widget:

.Creating a branch on Windows.
image::images/branch_widget_win.png[Creating a branch on Windows.]
.Creating a branch on Windows
image::images/branch_widget_win.png[Creating a branch on Windows]

Once your branch is created, making new commits is fairly straightforward.
Make some changes in your working directory, and when you switch to the GitHub client window, it will show you which files changed.
Enter a commit message, select the files you'd like to include, and click the ``Commit'' button (ctrl-enter or ⌘-enter).
Enter a commit message, select the files you'd like to include, and click the "`Commit`" button (ctrl-enter or ⌘-enter).

The main way you interact with other repositories over the network is through the ``Sync'' feature.
The main way you interact with other repositories over the network is through the "`Sync`" feature.
Git internally has separate operations for pushing, fetching, merging, and rebasing, but the GitHub clients collapse all of these into one multi-step feature.
Here's what happens when you click the Sync button:

Expand All @@ -149,5 +148,5 @@ However, if your workflow is different, or you want more control over how and wh
==== Other GUIs

There are a number of other graphical Git clients, and they run the gamut from specialized, single-purpose tools all the way to apps that try to expose everything Git can do.
The official Git website has a curated list of the most popular clients at http://git-scm.com/downloads/guis[].
The official Git website has a curated list of the most popular clients at https://git-scm.com/downloads/guis[].
A more comprehensive list is available on the Git wiki site, at https://git.wiki.kernel.org/index.php/Interfaces,_frontends,_and_tools#Graphical_Interfaces[].
10 changes: 10 additions & 0 deletions book/A-git-in-other-environments/sections/jetbrainsides.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== Git in IntelliJ / PyCharm / WebStorm / PhpStorm / RubyMine

JetBrains IDEs (such as IntelliJ IDEA, PyCharm, WebStorm, PhpStorm, RubyMine, and others) ship with a Git Integration plugin.
It provides a dedicated view in the IDE to work with Git and GitHub Pull Requests.

.Version Control ToolWindow in JetBrains IDEs
image::images/jb.png[Version Control ToolWindow in JetBrains IDEs]

The integration relies on the command-line git client, and requires one to be installed.
The official documentation is available at https://www.jetbrains.com/help/idea/using-git-integration.html[].
93 changes: 78 additions & 15 deletions book/A-git-in-other-environments/sections/powershell.asc
Original file line number Diff line number Diff line change
@@ -1,23 +1,86 @@
[[r_git_powershell]]
=== Git in Powershell
[[_git_powershell]]
=== Git in PowerShell

(((powershell)))(((tab completion, powershell)))(((shell prompts, powershell)))
(((PowerShell)))(((tab completion, PowerShell)))(((shell prompts, PowerShell)))
(((posh-git)))
The standard command-line terminal on Windows (`cmd.exe`) isn't really capable of a customized Git experience, but if you're using Powershell, you're in luck.
A package called Posh-Git (https://github.com/dahlbyk/posh-git[]) provides powerful tab-completion facilities, as well as an enhanced prompt to help you stay on top of your repository status.
The legacy command-line terminal on Windows (`cmd.exe`) isn't really capable of a customized Git experience, but if you're using PowerShell, you're in luck.
This also works if you're running PowerShell Core on Linux or macOS.
A package called posh-git (https://github.com/dahlbyk/posh-git[]) provides powerful tab-completion facilities, as well as an enhanced prompt to help you stay on top of your repository status.
It looks like this:

.Powershell with Posh-git.
image::images/posh-git.png[Powershell with Posh-git.]
.PowerShell with Posh-git
image::images/posh-git.png[PowerShell with Posh-git]

Just download a Posh-Git release from (https://github.com/dahlbyk/posh-git[]), and uncompress it to the `WindowsPowershell` directory.
Then open a Powershell prompt as the administrator, and do this:
==== Installation

===== Prerequisites (Windows only)

Before you're able to run PowerShell scripts on your machine, you need to set your local `ExecutionPolicy` to `RemoteSigned` (basically, anything except `Undefined` and `Restricted`).
If you choose `AllSigned` instead of `RemoteSigned`, also local scripts (your own) need to be digitally signed in order to be executed.
With `RemoteSigned`, only scripts having the `ZoneIdentifier` set to `Internet` (were downloaded from the web) need to be signed, others not.
If you're an administrator and want to set it for all users on that machine, use `-Scope LocalMachine`.
If you're a normal user, without administrative rights, you can use `-Scope CurrentUser` to set it only for you.

More about PowerShell Scopes: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes[].

More about PowerShell ExecutionPolicy: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy[].

To set the value of `ExecutionPolicy` to `RemoteSigned` for all users use the next command:

[source,powershell]
----
> Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy RemoteSigned -Force
----

===== PowerShell Gallery

If you have at least PowerShell 5 or PowerShell 4 with PackageManagement installed, you can use the package manager to install posh-git for you.

More information about PowerShell Gallery: https://docs.microsoft.com/en-us/powershell/scripting/gallery/overview[].

[source,powershell]
-----
> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm
> cd ~\Documents\WindowsPowerShell\posh-git
> .\install.ps1
-----
----
> Install-Module posh-git -Scope CurrentUser -Force
> Install-Module posh-git -Scope CurrentUser -AllowPrerelease -Force # Newer beta version with PowerShell Core support
----

If you want to install posh-git for all users, use `-Scope AllUsers` instead and execute the command from an elevated PowerShell console.
If the second command fails with an error like `Module 'PowerShellGet' was not installed by using Install-Module`, you'll need to run another command first:

[source,powershell]
----
> Install-Module PowerShellGet -Force -SkipPublisherCheck
----

Then you can go back and try again.
This happens, because the modules that ship with Windows PowerShell are signed with a different publishment certificate.

===== Update PowerShell Prompt

To include git information in your prompt, the posh-git module needs to be imported.
To have posh-git imported every time PowerShell starts, execute the `Add-PoshGitToProfile` command which will add the import statement into your `$profile` script.
This script is executed everytime you open a new PowerShell console.
Keep in mind, that there are multiple `$profile` scripts.
E. g. one for the console and a separate one for the ISE.

[source,powershell]
----
> Import-Module posh-git
> Add-PoshGitToProfile -AllHosts
----

===== From Source

Just download a posh-git release from https://github.com/dahlbyk/posh-git/releases[], and uncompress it.
Then import the module using the full path to the `posh-git.psd1` file:

[source,powershell]
----
> Import-Module <path-to-uncompress-folder>\src\posh-git.psd1
> Add-PoshGitToProfile -AllHosts
----

This will add the proper line to your `profile.ps1` file, and posh-git will be active the next time you open PowerShell.

This will add the proper line to your `profile.ps1` file, and posh-git will be active the next time you open your prompt.
For a description of the Git status summary information displayed in the prompt see: https://github.com/dahlbyk/posh-git/blob/master/README.md#git-status-summary-information[]
For more details on how to customize your posh-git prompt see: https://github.com/dahlbyk/posh-git/blob/master/README.md#customization-variables[].
Loading