Skip to content
代码片段 群组 项目
提交 4c14b7f2 编辑于 作者: Suzanne Selhorn's avatar Suzanne Selhorn
浏览文件

Merge branch 'eread/remove-duplicate-git-information-or-move-it' into 'master'

Remove duplicate Git information or move information to better place

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/138265



Merged-by: default avatarSuzanne Selhorn <sselhorn@gitlab.com>
Reviewed-by: default avatarEvan Read <eread@gitlab.com>
Co-authored-by: default avatarEvan Read <eread@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -86,6 +86,16 @@ repository.
To create a merge request, copy the link sent back from the remote
repository and paste it into a browser window.
## Add a file to the last commit
```shell
git add <filename>
git commit --amend
```
Append `--no-edit` to the `commit` command if you do not want to edit the commit
message.
## Related topics
- [Add file from the UI](../user/project/repository/index.md#add-a-file-from-the-ui)
......
......@@ -9,7 +9,7 @@ info: To determine the technical writer assigned to the Stage/Group associated w
In Git, if you make a mistake, you can undo or roll back your changes.
For more details, see [Undo options](numerous_undo_possibilities_in_git/index.md).
## Undo commits
## Undo commits by removing them
- Undo your last commit and put everything back in the staging area:
......@@ -37,7 +37,7 @@ For more details, see [Undo options](numerous_undo_possibilities_in_git/index.md
git reset --hard HEAD^^
```
## Git reset sample workflow
### Git reset sample workflow
1. Edit file again `edit_this_file.rb`.
1. Check status.
......@@ -63,6 +63,12 @@ git pull origin master
git push origin master
```
## Undo commits with a new replacement commit
```shell
git revert <commit-sha>
```
## The difference between `git revert` and `git reset`
- The `git reset` command removes the commit. The `git revert` command removes the changes but leaves the commit.
......
......@@ -9,75 +9,14 @@ type: reference
The following commands are frequently used.
## Remotes
## Add another URL to a remote
### Add another URL to a remote, so both remotes get updated on each push
Add another URL to a remote, so both remotes get updated on each push:
```shell
git remote set-url --add <remote_name> <remote_url>
```
### Revert a file to HEAD state and remove changes
To revert changes to a file, you can use either:
- `git checkout <filename>`
- `git reset --hard <filename>`
### Undo a previous commit by creating a new replacement commit
```shell
git revert <commit-sha>
```
### Create a new message for last commit
```shell
git commit --amend
```
### Create a new message for older commits
WARNING:
Changing commit history can disrupt others' work if they have cloned, forked, or have active branches.
Only amend pushed commits if you're sure it's safe.
To learn more, see [Git rebase and force push](git_rebase.md).
```shell
git rebase -i HEAD~n
```
Replace `n` with the number of commits you want to go back.
This opens your text editor with a list of commits.
In the editor, replace `pick` with `reword` for each commit you want to change the message:
```shell
reword 1fc6c95 original commit message
pick 6b2481b another commit message
pick 5c1291b another commit message
```
After saving and closing the file, you can update each message in a new editor window.
After updating your commits, you must push them to the repository.
As this rewrites history, a force push is required.
To prevent unintentional overwrites, use `--force-with-lease`:
```shell
git push --force-with-lease
```
### Add a file to the last commit
```shell
git add <filename>
git commit --amend
```
Append `--no-edit` to the `commit` command if you do not want to edit the commit
message.
## Refs and Log
### Use reflog to show the log of reference changes to HEAD
......@@ -190,4 +129,4 @@ questions that you know someone might ask.
Each scenario can be a third-level heading, for example `### 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. -->
\ No newline at end of file
but commented out to help encourage others to add to it in the future. -->
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册