As discussed in the
orderly introduction, you do not want to commit any files from
.outpack/
, drafts/
or archive/
(if used) to git as this will create all sorts of problems down the
line.
If you were directed here, it is probably because you have ended up with these files in git and want to undo this situation. The least painful way depends on your situation.
We have now put in guard rails to try and prevent this happening, but
it could still happen to you if you modify the .gitignore
file or force-add files for example.
Once you are in this situation, orderly2
will shout at
you:
orderly2::orderly_run("data")
## Error in `orderly2::orderly_run()`:
## ! Detected 6 outpack files committed to git
## ✖ Detected files were found in '.outpack/' and 'archive/'
## ℹ For tips on resolving this, please see
## <https://mrc-ide.github.io/orderly2/articles/troubleshooting.html>
## ℹ To turn this into a warning and continue anyway set the option
## 'orderly_git_error_is_warning' to TRUE by running
## options(orderly_git_error_is_warning = TRUE)
which may have directed you to this very page. If you just want to continue working anyway, then run the suggested command:
after which things will work with a warning the first time that session:
orderly2::orderly_run("data")
## Warning in orderly2::orderly_run("data"): Detected 6 outpack files committed to git
## ✖ Detected files were found in '.outpack/' and 'archive/'
## ℹ For tips on resolving this, please see
## <https://mrc-ide.github.io/orderly2/articles/troubleshooting.html>
## This warning is displayed once per session.
## ✔ Wrote '.gitignore'
## ℹ Starting packet 'data' `20241213-112038-734cd855` at 2024-12-13 11:20:38.455242
## > orderly2::orderly_artefact("data.rds", description = "Final data")
## > saveRDS(mtcars, "data.rds")
## ✔ Finished running 'data.R'
## ℹ Finished 20241213-112038-734cd855 at 2024-12-13 11:20:38.481721 (0.02647901 secs)
## [1] "20241213-112038-734cd855"
subsequent calls will not display the warning:
orderly2::orderly_run("data")
## ℹ Starting packet 'data' `20241213-112038-84ef8597` at 2024-12-13 11:20:38.524026
## > orderly2::orderly_artefact("data.rds", description = "Final data")
## > saveRDS(mtcars, "data.rds")
## ✔ Finished running 'data.R'
## ℹ Finished 20241213-112038-84ef8597 at 2024-12-13 11:20:38.54733 (0.02330446 secs)
## [1] "20241213-112038-84ef8597"
The rest of this section discusses how you might permanently fix the issue.
This is the case if you have just started a project, and are not yet collaborating on it with anyone else (or if that person is willing to re-clone their sources). The simplest thing to do is:
.git
directory entirelyorderly2::orderly_gitignore_update("(root)")
to set
up a reasonable .gitignore
that will prevent this situation
happening againgit add .
to add everything back in (review this
with git status
to make sure you’re happy)git commit -m "Initial commit"
to create a single
commit that contains all the files in currently in your repo with no
history, and also with no .outpack
filesIf you have previously pushed this repo to GitHub or similar then you will need to set that up again
git remote add origin https://github.com/user/repo
(replacing user/repo
with your path, or using
[email protected]:user/repo
if you use ssh to talk with
GitHub)git branch -M main
assuming you are using
main
for your default branch, which is now most commongit push --force -u origin main
Note that this is destructive and will require coordination with any collaborators as you have changed history.
If you do care about your history, but you also have only committed a
few files (e.g., you have committed files from .outpack/
which are small but not a large 100MB file in archive/
that
is preventing you pushing
to GitHub) then you could just delete the offending files from git
without updating the history, or affecting your local copies.
git rm --cached .outpack
(repeating with
draft
and archive
as needed)orderly2::orderly_gitignore_update("(root)")
to set
up a reasonable .gitignore
that will prevent this situation
happening againgit add .gitignore
to also stage thisgit commit -m "Delete unwanted outpack files"
You can then push this without any issues.
If you are working on a branch, and the unwanted files were committed
on that branch, the simplest thing to do is to copy the changes you have
made somewhere safe, create a new branch against the current
main
and copy those changes over there. You could do this
somewhat automatically by generating and applying a patch:
git diff -- src > changes.patch
git checkout main
git checkout -b changes-attempt2
git apply changes.patch
git push -u origin changes-attempt2
If the unwanted files have been committed onto your default branch, then you will have to do some potentially gory history rewriting. See this StackOverflow question, the git docs and the currently recommended tool for doing this. Good luck!