Commit d01db6ab authored by Suzanne Selhorn's avatar Suzanne Selhorn Committed by Amy Qualls

Edited undo git for style and Vale

parent 9ead4da9
...@@ -293,9 +293,9 @@ This output shows the repository history, including: ...@@ -293,9 +293,9 @@ This output shows the repository history, including:
To undo changes in the remote repository, you can create a new commit with the changes you To undo changes in the remote repository, you can create a new commit with the changes you
want to undo. You should follow this process, which preserves the history and want to undo. You should follow this process, which preserves the history and
provides a clear timeline and development structure. However, you only provides a clear timeline and development structure. However, you
need to follow this procedure if your work was merged into a branch that only need this procedure if your work was merged into a branch that
other developers are using as the base for their work (for example, `main`). other developers use as the base for their work.
![Use revert to keep branch flowing](img/revert.png) ![Use revert to keep branch flowing](img/revert.png)
...@@ -310,7 +310,7 @@ git revert B ...@@ -310,7 +310,7 @@ git revert B
You can undo remote changes and change history. You can undo remote changes and change history.
Even with an updated history, old commits can still be Even with an updated history, old commits can still be
accessed by commit SHA, at least until all the automated cleanup accessed by commit SHA. This is the case at least until all the automated cleanup
of detached commits is performed, or a cleanup is run manually. Even the cleanup might not remove old commits if there are still refs pointing to them. of detached commits is performed, or a cleanup is run manually. Even the cleanup might not remove old commits if there are still refs pointing to them.
![Modifying history causes problems on remote branch](img/rebase_reset.png) ![Modifying history causes problems on remote branch](img/rebase_reset.png)
...@@ -323,21 +323,21 @@ or a branch that might be used by other developers. ...@@ -323,21 +323,21 @@ or a branch that might be used by other developers.
When you contribute to large open source repositories, like [GitLab](https://gitlab.com/gitlab-org/gitlab), When you contribute to large open source repositories, like [GitLab](https://gitlab.com/gitlab-org/gitlab),
you can squash your commits into a single one. you can squash your commits into a single one.
A feature branch of a merge request is a public branch and might be used by To squash commits on a feature branch to a single commit on a target branch
other developers, but project process and rules might allow or require at merge, use `git merge --squash`.
you to use `git rebase` (command that changes history) to reduce number of
displayed commits on target branch after reviews are done (for example
GitLab). There is a `git merge --squash` command which does exactly that
(squashes commits on feature-branch to a single commit on target branch
at merge).
NOTE: NOTE:
Never modify the commit history of your [default branch](../../../user/project/repository/branches/default.md) or shared branch. Never modify the commit history of your [default branch](../../../user/project/repository/branches/default.md) or shared branch.
### How to change history ### How to change history
You can modify history by using `git rebase -i`. This command allows modification, squashing, deletion A feature branch of a merge request is a public branch and might be used by
of commits. other developers. However, the project rules might require
you to use `git rebase` to reduce the number of
displayed commits on target branch after reviews are done.
You can modify history by using `git rebase -i`. Use this command to modify, squash,
and delete commits.
```shell ```shell
# #
...@@ -360,41 +360,40 @@ of commits. ...@@ -360,41 +360,40 @@ of commits.
``` ```
NOTE: NOTE:
If you decide to abort, do not close your editor, because the history If you decide to stop a rebase, do not close your editor.
will change. Instead, remove all uncommented lines and save. Instead, remove all uncommented lines and save.
Use `git rebase` carefully on Use `git rebase` carefully on shared and remote branches.
shared and remote branches, but rest assured: nothing is broken until Experiment locally before you push to the remote repository.
you push back to the remote repository (so you can freely explore the
different outcomes locally).
```shell ```shell
# Modify history from commit-id to HEAD (current commit) # Modify history from commit-id to HEAD (current commit)
git rebase -i commit-id git rebase -i commit-id
``` ```
### Deleting sensitive information from commits ### Delete sensitive information from commits
You can use Git to delete sensitive information from your past commits. However,
history is modified in the process.
To rewrite history with
[certain filters](https://git-scm.com/docs/git-filter-branch#_options),
run `git filter-branch`.
Git also enables you to delete sensitive information from your past commits and To remove a file from the history altogether use:
it does modify history in the progress. That is why we have included it in this
section and not as a standalone topic. To do so, you should run the
`git filter-branch`, which enables you to rewrite history with
[certain filters](https://git-scm.com/docs/git-filter-branch#_options).
This command uses rebase to modify history and if you want to remove certain
file from history altogether use:
```shell ```shell
git filter-branch --tree-filter 'rm filename' HEAD git filter-branch --tree-filter 'rm filename' HEAD
``` ```
Because `git filter-branch` command might be slow on big repositories, there are The `git filter-branch` command might be slow on large repositories.
tools that can use some of Git specifics to enable faster execution of common Tools are available to execute Git commands more quickly.
tasks (which is exactly what removing sensitive information file is about).
An alternative is the open source community-maintained tool [BFG](https://rtyley.github.io/bfg-repo-cleaner/). An alternative is the open source community-maintained tool [BFG](https://rtyley.github.io/bfg-repo-cleaner/).
Keep in mind that these tools are faster because they do not provide the same These tools are faster because they do not provide the same
feature set as `git filter-branch` does, but focus on specific use cases. feature set as `git filter-branch` does, but focus on specific use cases.
Refer [Reduce repository size](../../../user/project/repository/reducing_the_repo_size_using_git.md) page to know more about purging files from repository history & GitLab storage. Refer to [Reduce repository size](../../../user/project/repository/reducing_the_repo_size_using_git.md) to
learn more about purging files from repository history and GitLab storage.
<!-- ## Troubleshooting <!-- ## Troubleshooting
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment