[Git] The following untracked working tree files would be overwritten 해결방법

홍승현·2022년 10월 25일
0

git

목록 보기
1/2

충돌

main에서 develop으로 checkout할 때 다음과 같은 오류가 발생했다.

error: The following untracked working tree files would be overwritten by checkout:
	FlipClock.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Please move or remove them before you switch branches.
Aborting

develop의 package파일이 main과 다르고, untrack(추적X) 하고 있기 때문에 checkout(브랜치 이동)할 때 overwritten(덮어씌우게) 된다는 것 같다.

해결방법

추적하지 않는 파일을 제거하면 된다.

# == 적용하지 않고 무엇을 해야할 지만 보고 싶을 때 ==
git clean -fd --dry-run # 또는
git clean -fdn

# == 적용하고 싶을 때 ==
git clean -fd
  • git clean: 추적하지 않는 파일 삭제
  • -fdn: 옵션 메서드
    • -f(--force): 강제 적용, 해당 옵션을 주지 않으면 특정 경우가 아닌경우 파일 또는 폴더 삭제를 거부합니다.
    • -d: 해당 옵션을 이용하여 untracked directory도 추적하여 삭제하도록 지정할 수 있습니다(제가 잘 해석했는 지 모르겠네요. 아래가 본글입니다.).
      • Normally, when no <path> is specified, git clean will not recurse into
            untracked directories to avoid removing too much. Specify -d to have it
            recurse into such directories as well. If any paths are specified, -d is
            irrelevant; all untracked files matching the specified paths (with
            exceptions for nested git directories mentioned under --force) will be
            removed.
    • -n(--dry-run): 실제로 적용하지 않고, 어떻게 적용했는지를 알려줍니다.
      • Don’t actually remove anything, just show what would be done.

  • -n(--dry-run) 적용 유무 차이
  • 해결완료
profile
블로그 이전: https://www.whitehyun.com

0개의 댓글