Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
77281b41
Commit
77281b41
authored
Aug 05, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
c2a4fb6e
a96c5644
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
211 additions
and
0 deletions
+211
-0
doc/topics/git/index.md
doc/topics/git/index.md
+1
-0
doc/topics/git/useful_git_commands.md
doc/topics/git/useful_git_commands.md
+210
-0
No files found.
doc/topics/git/index.md
View file @
77281b41
...
...
@@ -48,6 +48,7 @@ The following are resources about version control concepts:
The following resources may help you become more efficient at using Git:
-
[
Useful Git commands
](
useful_git_commands.md
)
collected by the GitLab support team.
-
[
Git Tips & Tricks
](
https://about.gitlab.com/2016/12/08/git-tips-and-tricks/
)
-
[
Eight Tips to help you work better with Git
](
https://about.gitlab.com/2015/02/19/8-tips-to-help-you-work-better-with-git/
)
...
...
doc/topics/git/useful_git_commands.md
0 → 100644
View file @
77281b41
---
type
:
reference
---
# Useful Git commands
Here are some useful Git commands collected by the GitLab support team. You may not
need to use often, but they can can come in handy when needed.
## Remotes
### Add another URL to a remote, so both remotes get updated on each push
```
sh
git remote set-url
--add
<remote_name> <remote_url>
```
## Staging and reverting changes
### Remove last commit and leave the changes in unstaged
```
sh
git reset
--soft
HEAD^
```
### Unstage a certain number of commits from HEAD
To unstage 3 commits, for example, run:
```
sh
git reset HEAD^3
```
### Unstage changes to a certain file from HEAD
```
sh
git reset <filename>
```
### Revert a file to HEAD state and remove changes
There are two options to revert changes to a file:
-
`git checkout <filename>`
-
`git reset --hard <filename>`
### Undo a previous commit by creating a new replacement commit
```
sh
git revert <commit-sha>
```
### Create a new message for last commit
```
sh
git commit
--amend
```
### Add a file to the last commit
```
sh
git add <filename>
git commit
--amend
```
Append
`--no-edit`
to the
`commit`
command if you do not want to edit the commit
message.
## Stashing
### Stash changes
```
sh
git stash save
```
The default behavor of
`stash`
is to save, so you can also use just:
```
sh
git stash
```
### Unstash your changes
```
sh
git stash apply
```
### Discard your stashed changes
```
sh
git stash drop
```
### Apply and drop your stashed changes
```
sh
git stash pop
```
## Refs and Log
### Use reflog to show the log of reference changes to HEAD
```
sh
git reflog
```
### Check the Git history of a file
The basic command to check the git history of a file:
```
sh
git log <file>
```
If you get this error message:
```
text
fatal: ambiguous argument <file_name>: unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
```
Use this to check the Git history of the file:
```
sh
git log
--
<file>
```
### Find the tags that contain a particular SHA
```
sh
git tag
--contains
<sha>
```
### Check the content of each change to a file
```
sh
gitk <file>
```
### Check the content of each change to a file, follows it past file renames
```
sh
gitk
--follow
<file>
```
## Debugging
### Use a custom SSH key for a git command
```
text
GIT_SSH_COMMAND="ssh -i ~/.ssh/gitlabadmin" git <command>
```
### Debug cloning
With SSH:
```
text
GIT_SSH_COMMAND="ssh -vvv" git clone <git@url>
```
With HTTPS:
```
text
GIT_TRACE_PACKET=1 GIT_TRACE=2 GIT_CURL_VERBOSE=1 git clone <url>
```
## Rebasing
### Rebase your branch onto master
The -i flag stands for 'interactive':
```
sh
git rebase
-i
master
```
### Continue the rebase if paused
```
sh
git rebase
--continue
```
### Use git rerere
To _reuse_ recorded solutions to the same problems when repeated:
```
sh
git rerere
```
To enable
`rerere`
functionality:
```
sh
git config
--global
rerere.enabled
true
```
<!-- ## Troubleshooting
Include any troubleshooting steps that you can foresee. If you know beforehand what issues
one might have when setting this up, or when something is changed, or on upgrading, it's
important to describe those, too. Think of things that may go wrong and include them here.
This is important to minimize requests for support, and to avoid doc comments with
questions that you know someone might ask.
Each scenario can be a third-level heading, e.g.
`### Getting error message X`
.
If you have none to add when creating a doc, leave this section in place
but commented out to help encourage others to add to it in the future. -->
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment